# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
22575 | 2017-04-30T05:39:39 Z | dried chocochip on Daegu asphalt(#897, suzy, zych1751, Acka) | Young Zebra (KRIII5_YZ) | C++11 | 500 ms | 145888 KB |
#include<bits/stdc++.h> using namespace std; int n, m; char mmap[3600][3600]; int cc[3600][3600], c_idx; bool visited[3600][3600]; int cc_sz[3600*3600+2]; int di[4] = {-1, 0, 1, 0}; int dj[4] = {0, 1, 0, -1}; void dfs(int i, int j) { visited[i][j] = true; cc[i][j] = c_idx; cc_sz[c_idx]++; for(int k = 0; k < 4; k++) { int ni = i+di[k], nj = j+dj[k]; if(ni < 0 || ni >= 9*n || nj < 0 || nj >= 9*m) continue; if(!visited[ni][nj] && mmap[i][j] == mmap[ni][nj]) dfs(ni, nj); } } int main() { scanf("%d %d", &n, &m); for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) scanf(" %c", &mmap[i][j]); for(int i = 0; i < 9*n; i++) for(int j = 0; j < 9*m; j++) mmap[i][j] = mmap[i%n][j%m]; for(int i = 0; i < 9*n; i++) for(int j = 0; j < 9*m; j++) if(!visited[i][j]) { c_idx++; dfs(i, j); } for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { bool check = false; for(int ddi = 0; ddi < 9; ddi++) for(int ddj = 0; ddj < 9; ddj++) { if(ddi == 4 && ddj == 4) continue; if(cc[i+n*4][j+m*4] == cc[i+ddi*n][j+ddj*m]) check = true; } if(check) printf("-1 "); else printf("%d ", cc_sz[cc[i+n*4][j+m*4]]); } printf("\n"); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 500 ms | 145888 KB | Execution timed out |
2 | Halted | 0 ms | 0 KB | - |