Advertisement
mickypinata

CUBE-T223: Erosion

May 29th, 2020
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. int row, col;
  6.  
  7. int main(){
  8.  
  9.     scanf("%d %d", &row, &col);
  10.     int memo[row + 1][col + 1];
  11.     char m[col + 10];
  12.     //vector<vector<int>> memo(row + 1, vector<int>(col + 1, 0));
  13.     vector<int> erode(max(row, col) + 1, 0);
  14.  
  15.     int cnt1 = 0;
  16.     for(int i = 1; i <= row; ++i){
  17.         scanf(" %s", &m);
  18.         for(int j = 1; j <= col; ++j){
  19.             if(m[j - 1] == '0'){
  20.                 memo[i][j] = 0;
  21.                 continue;
  22.             }
  23.             ++cnt1;
  24.             if(i == 1 || j == 1){
  25.                 memo[i][j] = 1;
  26.                 ++erode[1];
  27.             } else {
  28.                 memo[i][j] = min(memo[i - 1][j - 1], min(memo[i - 1][j], memo[i][j - 1])) + 1;
  29.                 ++erode[memo[i][j]];
  30.             }
  31.         }
  32.     }
  33.  
  34.     for(int i = 0; i <= min(row, col) - 1; ++i){
  35.         cout << cnt1 - erode[i] << "\n";
  36.         cnt1 -= erode[i];
  37.     }
  38.  
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement