Submission #22782

#TimeUsernameProblemLanguageResultExecution timeMemory
22782퍼플달고싶다 (#40)Young Zebra (KRIII5_YZ)C++98
7 / 7
426 ms40092 KiB
#include <bits/stdc++.h> #define pb push_back #define fi first #define se second #define SIZE 31600000 #define BC 50 #define BS 5000 #define MOD 1000000007LL #define MAXV 555 #define INF 0x3f3f3f3f #define INFL 0x3f3f3f3f3f3f3f3fLL using namespace std; typedef long long ll; typedef unsigned long long ull; typedef double db; typedef vector<vector<long long> > mat; int n,m; char str[444][444]; bool bd[1222][1222]; bool visited[1222][1222]; int sz[1222][1222]; pair<int, int> p[1222][1222]; int dy[4] = {-1,0,1,0}, dx[4] = {0,1,0,-1}; pair<int, int> find(pair<int, int> u) { if(p[u.fi][u.se] == u) return u; return p[u.fi][u.se] = find(p[u.fi][u.se]); } void merge(pair<int, int> u, pair<int, int> v) { u = find(u), v = find(v); if(u == v) return; p[u.fi][u.se] = v; sz[v.fi][v.se] += sz[u.fi][u.se]; } bool ok(int y, int x) {return y>=0 && y<3*n && x>=0 && x<3*m;} void bfs(int y, int x) { queue<pair<int, int > > q; q.push({y,x}); visited[y][x] = 1; while(!q.empty()) { int hy = q.front().fi, hx = q.front().se; // printf("here %d %d\n",hy,hx); q.pop(); for(int i=0;i<4;i++) { int ny = hy + dy[i], nx = hx + dx[i]; if(ny < 0) ny += 3*n; if(nx < 0) nx += 3*m; if(ny >= 3*n) ny -= 3*n; if(nx >= 3*m) nx -= 3*m; if(ok(ny,nx) && visited[ny][nx] == 0 && (bd[y][x] == bd[ny][nx])) { merge({y,x}, {ny,nx}), q.push({ny,nx}), visited[ny][nx] = 1; } } } } int ans[444][444]; int main () { for(int i=0;i<1222;i++) for(int j=0;j<1222;j++) p[i][j] = {i,j}, sz[i][j] = 1; scanf("%d%d",&n,&m); for(int i=0;i<n;i++) scanf("%s",str[i]); for(int yc=0;yc<3;yc++) for(int xc=0;xc<3;xc++) for(int i=0;i<n;i++) for(int j=0;j<m;j++) bd[yc*n+i][xc*m+j] = str[i][j] == 'B' ? 1 : 0; for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { int y = n+i, x = m+j; if(visited[y][x] == 0) bfs(y,x); pair<int, int> root = find({y,x}); ans[i][j] = sz[root.fi][root.se]; } } for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { pair<int, int> chk = find({i+n,j+m}); for(int yc=0;yc<3;yc++) { for(int xc=0;xc<3;xc++) { if(yc == 1 && xc == 1) continue; pair<int, int> chk2 = find({i+yc*n,j+xc*m}); if(chk == chk2) ans[i][j] = -1; } } printf("%d ",ans[i][j]); } printf("\n"); } // for(int i=0;i<100;i++) { // for(int j=0;j<100;j++) printf("%d ",sz[i][j]); // printf("\n"); // } }

Compilation message (stderr)

YZ.cpp: In function 'void bfs(int, int)':
YZ.cpp:42:9: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
  q.push({y,x});
         ^
YZ.cpp:42:14: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
  q.push({y,x});
              ^
YZ.cpp:55:11: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
     merge({y,x}, {ny,nx}), q.push({ny,nx}), visited[ny][nx] = 1;
           ^
YZ.cpp:55:18: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
     merge({y,x}, {ny,nx}), q.push({ny,nx}), visited[ny][nx] = 1;
                  ^
YZ.cpp:55:35: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
     merge({y,x}, {ny,nx}), q.push({ny,nx}), visited[ny][nx] = 1;
                                   ^
YZ.cpp:55:42: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
     merge({y,x}, {ny,nx}), q.push({ny,nx}), visited[ny][nx] = 1;
                                          ^
YZ.cpp: In function 'int main()':
YZ.cpp:64:64: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
  for(int i=0;i<1222;i++) for(int j=0;j<1222;j++) p[i][j] = {i,j}, sz[i][j] = 1;
                                                                ^
YZ.cpp:64:58: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
  for(int i=0;i<1222;i++) for(int j=0;j<1222;j++) p[i][j] = {i,j}, sz[i][j] = 1;
                                                          ^
YZ.cpp:78:31: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
    pair<int, int> root = find({y,x});
                               ^
YZ.cpp:85:30: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
    pair<int, int> chk = find({i+n,j+m});
                              ^
YZ.cpp:89:33: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
      pair<int, int> chk2 = find({i+yc*n,j+xc*m});
                                 ^
YZ.cpp:65:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&m);
                     ^
YZ.cpp:66:41: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=0;i<n;i++) scanf("%s",str[i]);
                                         ^
#Verdict Execution timeMemoryGrader output
Fetching results...