Submission #22719

#TimeUsernameProblemLanguageResultExecution timeMemory
22719King_God_OnionPringles (#40)Young Zebra (KRIII5_YZ)C++98
7 / 7
69 ms25236 KiB
#include<bits/stdc++.h> using namespace std; int rr[4] = {1,0,-1,0}; int cc[4] = {0,1,0,-1}; char bd[805][805]; int vis[2][805][805]; int n,m; int ans[160001], clr = 1; int my_clr[401][401], cntt[2][160001]; void dfs(int flag, int r, int c, int md){ //printf("%d %d %d %d %d %d\n",flag,r,c,bf,br,bc); cntt[md][clr]++; for(int i=0;i<4;i++){ int new_flag = flag, nr = r, nc = c; nr += rr[i]; nc += cc[i]; if(nr == -1){ nr = n-1; new_flag = 1; } if(nr == n){ nr = 0; new_flag = 1; } if(nc == -1){ nc = m-1; new_flag = 1; } if(nc == m){ nc = 0; new_flag = 1; } if(bd[r][c] == bd[nr][nc] && vis[new_flag][nr][nc] != clr){ vis[new_flag][nr][nc] = clr; dfs(new_flag, nr, nc, md); } } } int main(){ scanf("%d%d",&n,&m); for(int i=0;i<n;i++) scanf("%s",bd[i]); for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ if(vis[1][i][j] == 0){ vis[1][i][j] = clr; dfs(1,i,j,0); clr++; } my_clr[i][j] = vis[1][i][j]; } } n*=2;m*=2; for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ vis[1][i][j] = 0; bd[i][j] = bd[i%(n/2)][j%(m/2)]; } } for(int i=0;i<n/2;i++){ for(int j=0;j<m/2;j++){ if(ans[my_clr[i][j]] == 0){ clr = my_clr[i][j]; vis[1][i][j] = clr; dfs(1,i,j,1); if(cntt[0][clr] == cntt[1][clr]){ ans[clr] = cntt[0][clr]; }else{ ans[clr] = -1; } } printf("%d ",ans[my_clr[i][j]]); } printf("\n"); } }

Compilation message (stderr)

YZ.cpp: In function 'int main()':
YZ.cpp:41: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:42:43: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i=0;i<n;i++) scanf("%s",bd[i]);
                                           ^
#Verdict Execution timeMemoryGrader output
Fetching results...