Advertisement
mickypinata

SMMR-T041: Diamond Wall

Jun 3rd, 2021
691
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.10 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int N = 100;
  5.  
  6. int tower[N + 10][N + 10];
  7. int ans[4];
  8.  
  9. int main(){
  10.  
  11.     int row, col;
  12.     scanf("%d%d", &row, &col);
  13.     for(int i = 1; i <= row; ++i){
  14.         for(int j = 1; j <= col; ++j){
  15.             scanf("%d", &tower[i][j]);
  16.         }
  17.     }
  18.  
  19.     // North
  20.     ans[0] = 0;
  21.     for(int i = 1; i <= col; ++i){
  22.         int cnt = 0;
  23.         int last = 0;
  24.         for(int j = 1; j <= row; ++j){
  25.             if(tower[j][i] > last){
  26.                 last = tower[j][i];
  27.                 ++cnt;
  28.             }
  29.         }
  30.         ans[0] += cnt;
  31.     }
  32.  
  33.     // South
  34.     ans[1] = 0;
  35.     for(int i = 1; i <= col; ++i){
  36.         int cnt = 0;
  37.         int last = 0;
  38.         for(int j = row; j >= 1; --j){
  39.             if(tower[j][i] > last){
  40.                 last = tower[j][i];
  41.                 ++cnt;
  42.             }
  43.         }
  44.         ans[1] += cnt;
  45.     }
  46.  
  47.     // West
  48.     ans[2] = 0;
  49.     for(int i = 1; i <= row; ++i){
  50.         int cnt = 0;
  51.         int last = 0;
  52.         for(int j = 1; j <= col; ++j){
  53.             if(tower[i][j] > last){
  54.                 last = tower[i][j];
  55.                 ++cnt;
  56.             }
  57.         }
  58.         ans[2] += cnt;
  59.     }
  60.  
  61.     // East
  62.     ans[3] = 0;
  63.     for(int i = 1; i <= row; ++i){
  64.         int cnt = 0;
  65.         int last = 0;
  66.         for(int j = col; j >= 1; --j){
  67.             if(tower[i][j] > last){
  68.                 last = tower[i][j];
  69.                 ++cnt;
  70.             }
  71.         }
  72.         ans[3] += cnt;
  73.     }
  74.  
  75.     vector<int> tmp;
  76.     int mx = 0;
  77.     for(int i = 0; i < 4; ++i){
  78.         if(ans[i] > mx){
  79.             tmp.clear();
  80.             mx = ans[i];
  81.             tmp.push_back(i);
  82.         } else if(ans[i] == mx){
  83.             tmp.push_back(i);
  84.         }
  85.     }
  86.  
  87.     if(tmp.size() > 1){
  88.         cout << "So many ways\n";
  89.     } else if(tmp[0] == 0){
  90.         cout << "North\n";
  91.     } else if(tmp[0] == 1){
  92.         cout << "South\n";
  93.     } else if(tmp[0] == 2){
  94.         cout << "West\n";
  95.     } else if(tmp[0] == 3){
  96.         cout << "East\n";
  97.     }
  98.     cout << mx;
  99.  
  100.     return 0;
  101. }
  102.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement