Submission #1056909

#TimeUsernameProblemLanguageResultExecution timeMemory
1056909NickpapadakGame (eJOI20_game)C++14
0 / 100
0 ms348 KiB
#include<bits/stdc++.h> using namespace std; const unsigned int MAXN = (int)2e+1 + 5; const unsigned int MAXMN = 410; int grid[MAXN][MAXN]; int N, M; int cnt; int p[MAXMN]; int sz[MAXMN]; int CI(int x, int y) {return (y-1)*M + x;} int findp(int u){ if(p[u] == u) return u; return p[u] = findp(p[u]); } void Union(int u, int v){ if(findp(v) == findp(u)) return; if(sz[findp(v)] > sz[findp(u)]) swap(u,v); sz[findp(u)] += sz[findp(v)]; // int x = findp(u), y = findp(v); // printf("%d\n", findp(v)); // p[2]= 1; p[findp(v)] = findp(u); } void Join(int x, int y, int dx, int dy){ // printf("\n\n%d %d\n\n", x, y); if(x < 1 || x > M || y < 0 || y > N) return; if(dx < 1 || dx > M || dy < 0 || dy > N) return; Union(CI(x,y), CI(dx,dy)); } int main(){ scanf("%d%d", &N, &M); for(int i = 1; i<= N*M; ++i){ p[i] = i; sz[i] = 1; } char ps[M]; scanf("%s", ps); for(int i = 1; i<=N; ++i){ char s[M]; scanf("%s", s); for(int j = 1; j <=M;++j){ grid[i][j] = (ps[j-1]-'0') + (s[j-1]-'0'); if(s[j-1]-'0' == 0) Join(j, i, j, i+1); } for(int j = 0; j<M;++j){ ps[j] = s[j]; } } for(int i = 1; i<=N; ++i){ char s[M+1]; scanf("%s", s); for(int j = 1; j<=M; ++j){ grid[i][j] += (s[j] -'0') + (s[j-1] - '0'); if(s[j-1] == '0') Join(j, i, j-1, i); if(grid[i][j] == 4) cnt++; } } int f = 0, s = 0; bool onlytwo = true; for(int i = 1; i<=M*N;++i){ if(f==0)f = findp(i); else if(s==0 && f != findp(i)) s= findp(i); else if(findp(i) != s && findp(i) != f) onlytwo = false; } if(onlytwo){ if(sz[findp(f)] > 1 && sz[findp(s)] > 1) printf("%d", 2 - (findp(f)+findp(s))); else if(sz[findp(f)] ==1 && sz[findp(s)] > 1) printf("%d", (sz[findp(s)]) - 1); else if(sz[findp(s)] ==1 && sz[findp(f)] > 1) printf("%d", (sz[findp(f)]) - 1); else printf("0"); } // for(int i = 1; i<=N;++i){ // for(int j = 1; j <=M;++j){ // printf("%d ", grid[i][j]); // } // printf("\n"); // } return 0; }

Compilation message (stderr)

game.cpp: In function 'int main()':
game.cpp:35:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |     scanf("%d%d", &N, &M);
      |     ~~~~~^~~~~~~~~~~~~~~~
game.cpp:41:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |     scanf("%s", ps);
      |     ~~~~~^~~~~~~~~~
game.cpp:44:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |         scanf("%s", s);
      |         ~~~~~^~~~~~~~~
game.cpp:56:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |         scanf("%s", s);
      |         ~~~~~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...