Submission #22644

#TimeUsernameProblemLanguageResultExecution timeMemory
22644dried chocochip on Daegu asphalt (#40)Young Zebra (KRIII5_YZ)C++11
2 / 7
33 ms10916 KiB
#include<bits/stdc++.h> using namespace std; int n, m; char mmap[400][400]; int cc[400][400], c_idx; bool visited[400][400]; int cc_sz[400*400+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 += n; if(ni >= n) ni -= n; if(nj < 0) nj += m; if(nj >= m) nj -= m; 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 < n; i++) for(int j = 0; j < 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++) printf("%d ", cc_sz[cc[i][j]]); printf("\n"); } return 0; }

Compilation message (stderr)

YZ.cpp: In function 'int main()':
YZ.cpp:34:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &m);
                        ^
YZ.cpp:37:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf(" %c", &mmap[i][j]);
                             ^
#Verdict Execution timeMemoryGrader output
Fetching results...