Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.28 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int T = 12;
  5. int mat[T][T];
  6. int ri[T][T];
  7. int le[T][T];
  8. bool po[T][T];
  9. int n,m,p;
  10.  
  11. int main() {
  12.     cin >> n >> m >> p;
  13.     while(n or m or p) {
  14.         p--;
  15.  
  16.         for(int i = 0; i < n; i++) {
  17.             for(int j = 0; j < m; j++) {
  18.                 cin >> mat[i][j];
  19.                 if(mat[i][j]) po[i][j] = 1;
  20.                 else po[i][j] = 0;
  21.             }
  22.         }
  23.  
  24.         for(int i = 0; i < n; i++) {
  25.             for(int j = 1; j < m; j++) {
  26.                 if(mat[i][j]) le[i][j] = mat[i][j];
  27.                 else le[i][j] = le[i][j-1];
  28.             }
  29.         }
  30.         for(int i = 0; i < n; i++){
  31.             for(int j = m-1; j >= 0; j--) {
  32.                 if(mat[i][j]) ri[i][j] = mat[i][j];
  33.                 else ri[i][j] = ri[i][j+1];
  34.             }
  35.         }
  36.  
  37.         int i = 0;
  38.         bool flag = 0;
  39.  
  40.         while(i < n) {
  41.             if(ri[i][p] > le[i][p]) {
  42.                 int x = ri[i][p] - le[i][p];
  43.                 int z = p-x;
  44.                 for(; p >= z and !flag; p--) {
  45.                     if(p < 0 or po[i][p]) { cout << "BOOM " << i+1 << " " << p+1 << endl; flag = 1; }
  46.                 }
  47.                 p++;
  48.             }
  49.             else if(le[i][p] > ri[i][p]) {
  50.                 int x = le[i][p] - ri[i][p];
  51.  
  52.                 int z = p+x;
  53.                 for(; p <= z and !flag; p++) {
  54.                     if(p >= m or po[i][p]) { cout << "BOOM " << i+1 << " " << p+1 << endl; flag = 1; }
  55.                 }
  56.                 p--;
  57.  
  58.             }
  59.             i++;
  60.         }
  61.  
  62.         if(!flag) cout << "OUT " << p+1 << endl;
  63.        
  64.         cin >> n >> m >> p;
  65.     }
  66.  
  67.     return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement