Advertisement
mickypinata

GCJ2018-2T1: Falling Balls

Jun 21st, 2021
1,243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.60 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int N = 100;
  5.  
  6. int tr[N + 10];
  7.  
  8. int main(){
  9.  
  10.     int Q;
  11.     scanf("%d", &Q);
  12.     for(int q = 1; q <= Q; ++q){
  13.         cout << "Case #" << q << ": ";
  14.         char board[N + 10][N + 10] = {};
  15.         int col;
  16.         scanf("%d", &col);
  17.         for(int i = 1; i <= col; ++i){
  18.             scanf("%d", &tr[i]);
  19.         }
  20.         if(tr[1] == 0 || tr[col] == 0){
  21.             cout << "IMPOSSIBLE\n";
  22.             continue;
  23.         }
  24.         int bIdx = 1;
  25.         int tIdx = 1;
  26.         int currRow = 0;
  27.         while(bIdx < col){
  28.             if(tr[tIdx] == 0){
  29.                 ++tIdx;
  30.                 continue;
  31.             }
  32.             if(tIdx < bIdx){
  33.                 int i = 1;
  34.                 for(int j = bIdx; j > tIdx; --j){
  35.                     board[i][j] = '/';
  36.                     currRow = max(currRow, i);
  37.                     ++i;
  38.                 }
  39.             } else if(tIdx > bIdx){
  40.                 int i = 1;
  41.                 for(int j = bIdx; j < tIdx; ++j){
  42.                     board[i][j] = '\\';
  43.                     currRow = max(currRow, i);
  44.                     ++i;
  45.                 }
  46.             }
  47.             --tr[tIdx];
  48.             ++bIdx;
  49.         }
  50.         cout << currRow + 1 << '\n';
  51.         for(int i = 1; i <= currRow + 1; ++i){
  52.             for(int j = 1; j <= col; ++j){
  53.                 if(board[i][j] == '\0'){
  54.                     cout << '.';
  55.                 } else {
  56.                     cout << board[i][j];
  57.                 }
  58.             }
  59.             cout << '\n';
  60.         }
  61.     }
  62.  
  63.     return 0;
  64. }
  65.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement