Submission #147438

#TimeUsernameProblemLanguageResultExecution timeMemory
147438usernameVirus Experiment (JOI19_virus)C++14
Compilation error
0 ms0 KiB
int dx[4] = {-1,0,1,0}; int dy[4] = {0,-1,0,1}; char D[200000]; int U[800][800]; int tt[16]; int parent[640000]; int find(int n) { if (parent[n] != n) parent[n] = find(parent[n]); return parent[n]; } int done[640000]; queue<pii> Q; int visited[800][800]; int main() { int i,j; int M,R,C; scanf("%d %d %d",&M,&R,&C); for (i = 0; i < M; i++) scanf(" %c",&D[i]),D[i+M] = D[i]; for (i = 0; i < R; i++) { for (j = 0; j < C; j++) scanf("%d",&U[i][j]); } for (i = 1; i < 16; i++) { int p = -1; for (j = 0; j < 2*M; j++) { int yes; if (D[j] == 'W') yes = (i & 1); else if (D[j] == 'N') yes = (i & 2); else if (D[j] == 'E') yes = (i & 4); else yes = (i & 8); if (yes) tt[i] = max(tt[i],j-p); else p = j; } if (tt[i] >= M) tt[i] = 100001; } int k,l,f = 1,t = 0; int best = R*C+1,num = 1; for (i = 0; i < R*C; i++) parent[i] = i; while (f) { f = 0; for (i = 0; i < R; i++) { for (j = 0; j < C; j++) { if ((U[i][j] > 0) && !done[i*C+j] && (find(i*C+j) == i*C+j)) { int c = 0,mx = -1,my = -1; visited[i][j] = ++t,Q.push(mp(i,j)); while (!Q.empty()) { int x = Q.front().second,y = Q.front().first; Q.pop(),c++; for (k = 0; k < 4; k++) { int xx = x+dx[k],yy = y+dy[k]; if ((xx >= 0) && (xx < C) && (yy >= 0) && (yy < R) && (visited[yy][xx] != t) && (U[yy][xx] > 0)) { int m = 0; for (l = 0; l < 4; l++) { int x2 = xx+dx[l],y2 = yy+dy[l]; if ((x2 >= 0) && (x2 < C) && (y2 >= 0) && (y2 < R) && (visited[y2][x2] == t)) m |= (1 << l); } if (tt[m] >= U[yy][xx]) { if (find(yy*C+xx) != i*C+j) mx = xx,my = yy; visited[yy][xx] = t; Q.push(mp(yy,xx)); if(mx != -1)break; } } } if (mx != -1) break; } while (!Q.empty()) Q.pop(); if (mx == -1) { if (c < best) best = num = c; else if (c == best) num += c; done[i*C+j] = 1; } // else if (done[find(my*C+mx)]) done[i*C+j] = 1; else parent[i*C+j] = find(my*C+mx); f = 1; } } } } printf("%d\n%d\n",best,num); return 0; }

Compilation message (stderr)

virus.cpp:12:1: error: 'queue' does not name a type
 queue<pii> Q;
 ^~~~~
virus.cpp: In function 'int main()':
virus.cpp:17:5: error: 'scanf' was not declared in this scope
     scanf("%d %d %d",&M,&R,&C);
     ^~~~~
virus.cpp:31:30: error: 'max' was not declared in this scope
             if (yes) tt[i] = max(tt[i],j-p);
                              ^~~
virus.cpp:31:30: note: suggested alternative: 'main'
             if (yes) tt[i] = max(tt[i],j-p);
                              ^~~
                              main
virus.cpp:45:41: error: 'Q' was not declared in this scope
                     visited[i][j] = ++t,Q.push(mp(i,j));
                                         ^
virus.cpp:45:48: error: 'mp' was not declared in this scope
                     visited[i][j] = ++t,Q.push(mp(i,j));
                                                ^~
virus.cpp:45:48: note: suggested alternative: 'my'
                     visited[i][j] = ++t,Q.push(mp(i,j));
                                                ^~
                                                my
virus.cpp:51:51: error: 'y' was not declared in this scope
                             int xx = x+dx[k],yy = y+dy[k];
                                                   ^
virus.cpp:51:51: note: suggested alternative: 'yy'
                             int xx = x+dx[k],yy = y+dy[k];
                                                   ^
                                                   yy
virus.cpp:81:5: error: 'printf' was not declared in this scope
     printf("%d\n%d\n",best,num);
     ^~~~~~
virus.cpp:81:5: note: suggested alternative: 'parent'
     printf("%d\n%d\n",best,num);
     ^~~~~~
     parent