Advertisement
YEZAELP

J. Robot Factory

Nov 6th, 2021
789
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. using pi = pair <int, int>;
  5. using pii = pair <int, pi>;
  6. const int N = 1e3 + 10;
  7. const int M = 1e3 + 10;
  8. int di[] = {0, 1, 0, -1};
  9. int dj[] = {-1, 0, 1, 0};
  10. int ar[N][M];
  11. bool vs[N][M];
  12. int n, m;
  13.  
  14. int Size(int ui, int uj){
  15.     vs[ui][uj] = true;
  16.     int dis = 1;
  17.     for(int dij = 0, drt = ar[ui][uj]; dij < 4; dij ++, drt >>= 1){
  18.         int vi = ui + di[dij];
  19.         int vj = uj + dj[dij];
  20.         if((drt&1) == 0 and !vs[vi][vj])
  21.             dis += Size(vi, vj);
  22.     }
  23.     return dis;
  24. }
  25.  
  26. int main(){
  27.  
  28.     scanf("%d%d", &n, &m);
  29.  
  30.     for(int i=1;i<=n;i++){
  31.         for(int j=1;j<=m;j++){
  32.             scanf("%d", &ar[i][j]);
  33.         }
  34.     }
  35.  
  36.     vector <int> room;
  37.  
  38.     for(int i=1;i<=n;i++){
  39.         for(int j=1;j<=m;j++){
  40.             if(!vs[i][j])
  41.                 room.push_back(Size(i, j));
  42.         }
  43.     }
  44.  
  45.     sort(room.begin(), room.end());
  46.     int sz = room.size();
  47.     for(int i=sz-1;i>=0;i--)
  48.         printf("%d ", room[i]);
  49.  
  50.     return 0;
  51. }
Advertisement
RAW Paste Data Copied
Advertisement