Submission #45427

#TimeUsernameProblemLanguageResultExecution timeMemory
45427choikiwonYoung Zebra (KRIII5_YZ)C++17
7 / 7
71 ms7148 KiB
#include<bits/stdc++.h> using namespace std; typedef pair<int, int> pii; int dx[4] = {1, -1, 0, 0}; int dy[4] = {0, 0, 1, -1}; int N, M; char G[402][402]; int vis[402][402]; pii dist[402][402]; int sz[1000010]; int main() { scanf("%d %d", &N, &M); for(int i = 0; i < N; i++) { scanf("\n"); for(int j = 0; j < M; j++) { scanf("%c", &G[i][j]); } } memset(vis, -1, sizeof(vis)); int ccnt = 0; for(int i = 0; i < N; i++) { for(int j = 0; j < M; j++) { if(vis[i][j] != -1) continue; queue<int> q; q.push(i * M + j); vis[i][j] = ccnt; int inf = 0; int cnt = 1; while(!q.empty()) { int u = q.front(); q.pop(); int r = u / M; int c = u % M; for(int k = 0; k < 4; k++) { int nr = (r + dy[k] + N) % N; int nc = (c + dx[k] + M) % M; pii nd = dist[r][c]; if(r + dy[k] < 0) nd.first--; if(r + dy[k] >= N) nd.first++; if(c + dx[k] < 0) nd.second--; if(c + dx[k] >= M) nd.second++; if(G[nr][nc] != G[r][c]) continue; if(vis[nr][nc] != -1) { if(dist[nr][nc] != nd) { inf = 1; } continue; } cnt++; q.push(nr * M + nc); vis[nr][nc] = ccnt; dist[nr][nc] = nd; } } sz[ccnt] = inf? -1 : cnt; ccnt++; } } for(int i = 0; i < N; i++) { for(int j = 0; j < M; j++) { printf("%d ", sz[ vis[i][j] ]); } printf("\n"); } }

Compilation message (stderr)

YZ.cpp: In function 'int main()':
YZ.cpp:16:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &N, &M);
     ~~~~~^~~~~~~~~~~~~~~~~
YZ.cpp:19:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("\n");
         ~~~~~^~~~~~
YZ.cpp:21:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%c", &G[i][j]);
             ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...