# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
23114 | 2017-05-03T06:28:35 Z | sgc109 | Young Zebra (KRIII5_YZ) | C++11 | 196 ms | 15648 KB |
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9+7; const int INF = 0x3c3c3c3c; const long long INFL = 0x3c3c3c3c3c3c3c3c; int N,M; char pane[403][403]; char pane2[1203][1203]; int parent[1440003]; int size[1440003]; int calcId(int i, int j){ return i*3*M + j; } int find(int p){ if(p==parent[p]) return p; return parent[p] = find(parent[p]); } void merge(int a, int b){ a = find(a), b = find(b); if(a==b) return; parent[a] = b; size[b] += size[a]; } bool inRange(int i, int j){ return 0 <= i && i < 3*N && 0 <= j && j < 3*M; } int main() { for(int i = 0 ; i < 1440003; i++) parent[i] = i, size[i] = 1; scanf("%d%d", &N, &M); for(int i = 0 ; i < N ; i++){ scanf("%s",pane[i]); } for(int i = 0 ; i < 3*N; i++){ for(int j = 0 ; j < 3*M; j++){ pane2[i][j] = pane[i%N][j%M]; } } for(int i = 0 ; i < 3*N; i++){ for(int j = 0 ; j < 3*M; j++){ for(int k = 0 ; k < 4; k++){ int ni = (i+"1201"[k]-'1'+3*N)%(3*N); int nj = (j+"2110"[k]-'1'+3*M)%(3*M); if(!inRange(ni, nj) || pane2[i][j] != pane2[ni][nj]) continue; merge(calcId(i, j), calcId(ni, nj)); } } } for(int i = N; i < 2*N; i++){ for(int j = M; j < 2*M; j++){ for(int k = 0 ; k < 8; k++){ int ni = i+("12010202"[k]-'0'-1)*N; int nj = j+("21100022"[k]-'0'-1)*M; if(find( calcId(i, j) ) == find( calcId(ni, nj) )) size[find(calcId(i, j))] = -1; } } } for(int i = N; i < 2*N; i++){ for(int j = M; j < 2*M; j++){ printf("%d ",size[find(calcId(i, j))]); } printf("\n"); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 173 ms | 14840 KB | Output is correct |
2 | Correct | 166 ms | 14840 KB | Output is correct |
3 | Correct | 173 ms | 14840 KB | Output is correct |
4 | Correct | 183 ms | 14840 KB | Output is correct |
5 | Correct | 179 ms | 14840 KB | Output is correct |
6 | Correct | 163 ms | 14840 KB | Output is correct |
7 | Correct | 163 ms | 14840 KB | Output is correct |
8 | Correct | 136 ms | 14988 KB | Output is correct |
9 | Correct | 159 ms | 14840 KB | Output is correct |
10 | Correct | 129 ms | 15020 KB | Output is correct |
11 | Correct | 166 ms | 14840 KB | Output is correct |
12 | Correct | 163 ms | 14840 KB | Output is correct |
13 | Correct | 163 ms | 14840 KB | Output is correct |
14 | Correct | 136 ms | 14840 KB | Output is correct |
15 | Correct | 153 ms | 14840 KB | Output is correct |
16 | Correct | 136 ms | 14840 KB | Output is correct |
17 | Correct | 116 ms | 15648 KB | Output is correct |
18 | Correct | 129 ms | 15644 KB | Output is correct |
19 | Correct | 169 ms | 14840 KB | Output is correct |
20 | Correct | 196 ms | 14840 KB | Output is correct |
21 | Correct | 133 ms | 14840 KB | Output is correct |
22 | Correct | 143 ms | 14840 KB | Output is correct |
23 | Correct | 196 ms | 14840 KB | Output is correct |
24 | Correct | 163 ms | 14840 KB | Output is correct |
25 | Correct | 153 ms | 14840 KB | Output is correct |
26 | Correct | 3 ms | 14840 KB | Output is correct |
27 | Correct | 3 ms | 14840 KB | Output is correct |
28 | Correct | 3 ms | 14840 KB | Output is correct |
29 | Correct | 3 ms | 14840 KB | Output is correct |
30 | Correct | 3 ms | 14840 KB | Output is correct |
31 | Correct | 3 ms | 14840 KB | Output is correct |
32 | Correct | 0 ms | 14840 KB | Output is correct |
33 | Correct | 3 ms | 14840 KB | Output is correct |
34 | Correct | 0 ms | 14840 KB | Output is correct |
35 | Correct | 3 ms | 14840 KB | Output is correct |
36 | Correct | 9 ms | 14840 KB | Output is correct |
37 | Correct | 13 ms | 14840 KB | Output is correct |
38 | Correct | 13 ms | 14840 KB | Output is correct |
39 | Correct | 16 ms | 14840 KB | Output is correct |
40 | Correct | 9 ms | 14840 KB | Output is correct |