Submission #22830

#TimeUsernameProblemLanguageResultExecution timeMemory
22830dried chocochip on Daegu asphalt (#40)Young Zebra (KRIII5_YZ)C++11
2 / 7
43 ms11076 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}; int mod(int val, int m) { while(val < 0) val += m*m*m; return val%m; } int si, sj; bool cc_inf[400*400+2]; void dfs(int i, int j) { int ii = mod(i, n), jj = mod(j, m); visited[ii][jj] = true; cc[ii][jj] = c_idx; cc_sz[c_idx]++; for(int k = 0; k < 4; k++) { int ni = i+di[k], nj = j+dj[k]; int nii = mod(ni, n), njj = mod(nj, m); if(!(si == ni && sj == nj)) if(si == nii && sj == njj) cc_inf[c_idx] = true; if(!visited[nii][njj] && mmap[ii][jj] == mmap[nii][njj]) 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]) { si = i, sj = j; c_idx++; dfs(i, j); } for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) printf("%d ", cc_inf[cc[i][j]] ? -1 : cc_sz[cc[i][j]]); printf("\n"); } return 0; }

Compilation message (stderr)

YZ.cpp: In function 'int main()':
YZ.cpp:46: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:49: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...