# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
22782 | 2017-04-30T07:26:55 Z | 퍼플달고싶다(#990, smu201111192, pce913, cokcjswo) | Young Zebra (KRIII5_YZ) | C++ | 426 ms | 40092 KB |
#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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 209 ms | 29796 KB | Output is correct |
2 | Correct | 159 ms | 38524 KB | Output is correct |
3 | Correct | 169 ms | 28252 KB | Output is correct |
4 | Correct | 136 ms | 26216 KB | Output is correct |
5 | Correct | 106 ms | 25336 KB | Output is correct |
6 | Correct | 79 ms | 24224 KB | Output is correct |
7 | Correct | 413 ms | 28876 KB | Output is correct |
8 | Correct | 189 ms | 40092 KB | Output is correct |
9 | Correct | 376 ms | 40076 KB | Output is correct |
10 | Correct | 149 ms | 25164 KB | Output is correct |
11 | Correct | 103 ms | 25768 KB | Output is correct |
12 | Correct | 109 ms | 25764 KB | Output is correct |
13 | Correct | 273 ms | 27476 KB | Output is correct |
14 | Correct | 149 ms | 27644 KB | Output is correct |
15 | Correct | 313 ms | 36396 KB | Output is correct |
16 | Correct | 169 ms | 24924 KB | Output is correct |
17 | Correct | 146 ms | 27072 KB | Output is correct |
18 | Correct | 69 ms | 26992 KB | Output is correct |
19 | Correct | 66 ms | 23400 KB | Output is correct |
20 | Correct | 266 ms | 40028 KB | Output is correct |
21 | Correct | 363 ms | 28208 KB | Output is correct |
22 | Correct | 426 ms | 28100 KB | Output is correct |
23 | Correct | 253 ms | 38496 KB | Output is correct |
24 | Correct | 206 ms | 33756 KB | Output is correct |
25 | Correct | 239 ms | 31580 KB | Output is correct |
26 | Correct | 9 ms | 23400 KB | Output is correct |
27 | Correct | 9 ms | 23400 KB | Output is correct |
28 | Correct | 13 ms | 23668 KB | Output is correct |
29 | Correct | 16 ms | 23668 KB | Output is correct |
30 | Correct | 9 ms | 23400 KB | Output is correct |
31 | Correct | 9 ms | 23400 KB | Output is correct |
32 | Correct | 9 ms | 23400 KB | Output is correct |
33 | Correct | 6 ms | 23400 KB | Output is correct |
34 | Correct | 6 ms | 23400 KB | Output is correct |
35 | Correct | 6 ms | 23400 KB | Output is correct |
36 | Correct | 13 ms | 24720 KB | Output is correct |
37 | Correct | 19 ms | 24500 KB | Output is correct |
38 | Correct | 13 ms | 23400 KB | Output is correct |
39 | Correct | 19 ms | 24496 KB | Output is correct |
40 | Correct | 16 ms | 24720 KB | Output is correct |