Advertisement
YEZAELP

JAM: Falling Balls

Jun 22nd, 2021
1,003
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.00 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. #define s second
  5. #define f first
  6. const int N = 100;
  7. using pi = pair <int, int>;
  8. vector <pi> fall;
  9. char Ball[N+10][N+10];
  10. bool block[N+10];
  11. int n, m, ball;
  12.  
  13. void Setting();
  14. void Print();
  15.  
  16. void Left(int s, int e){ /// s < e
  17.     for(int i=1,j=e;j>=s;j--,i++){
  18.         Ball[i][j] = '\\';
  19.         n = max(n, i);
  20.     }
  21. }
  22.  
  23. void Right(int s, int e){ /// s < e
  24.     for(int i=1,j=s;j<=e;j++,i++){
  25.         Ball[i][j] = '/';
  26.         n = max(n, i);
  27.     }
  28. }
  29.  
  30. bool f(){
  31.  
  32.     scanf("%d", &m);
  33.  
  34.     int sum = 0;
  35.     bool sted = false;
  36.     for(int i=1;i<=m;i++) {
  37.         int x; scanf("%d", &x);
  38.         if(x > 0) fall.push_back({x, i});
  39.         if((i == 1 or i == m) and x == 0) sted = true;
  40.         sum += x;
  41.     }
  42.  
  43.     if(sted) return false;
  44.  
  45.     int sz = fall.size();
  46.     ball = 1;
  47.     for(int i=0;i<sz;i++){
  48.         int d = fall[i].f;
  49.         int s = ball;
  50.         int e = ball + d - 1;
  51.         if(s < fall[i].s) Left(s, fall[i].s - 1);
  52.         if(fall[i].s < e) Right(fall[i].s + 1, e);
  53.         ball = e + 1;
  54.     }
  55.  
  56.     return true;
  57. }
  58.  
  59.  
  60. int main(){
  61.  
  62.     int Q;
  63.     scanf("%d", &Q);
  64.  
  65.     for(int q=1;q<=Q;q++){
  66.         Setting();
  67.         bool ans = f();
  68.         printf("Case #%d: ", q);
  69.         if(!ans) printf("IMPOSSIBLE\n");
  70.         else Print();
  71.     }
  72.  
  73.     return 0;
  74. }
  75.  
  76. void Print(){
  77.     printf("%d\n", n+1);
  78.     for(int i=n;i>=0;i--){ // 0 = bottom
  79.         for(int j=1;j<=m;j++){
  80.             printf("%c", Ball[i][j]);
  81.         }
  82.         printf("\n");
  83.     }
  84. }
  85.  
  86. void Setting(){
  87.     for(int i=0;i<=N;i++){
  88.         for(int j=1;j<=N;j++){
  89.             Ball[i][j] = '.';
  90.         }
  91.     }
  92.     if(!fall.empty()) fall.clear();
  93.     n = 0;
  94. }
  95.  
  96. /*
  97.  
  98. 1
  99. 8
  100. 7 0 0 0 0 0 0 1
  101. Case #1: 7
  102. ....../.
  103. ...../..
  104. ..../...
  105. .../....
  106. ../.....
  107. ./......
  108. ........
  109.  
  110. 1
  111. 10
  112. 1 2 3 3 0 0 0 0 0 1
  113. Case #1: 6
  114. ......../.
  115. ......./..
  116. .....//...
  117. ....//....
  118. ..///.....
  119. ..........
  120.  
  121.  
  122. 1
  123. 10
  124. 1 0 0 5 0 0 3 0 0 1
  125.  
  126. 1
  127. 8
  128. 3 0 3 1 0 0 0 1
  129.  
  130. */
  131.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement