# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
516513 | 2022-01-21T12:41:02 Z | leinad2 | Furniture (JOI20_furniture) | C++17 | 438 ms | 19184 KB |
#include<bits/stdc++.h> using namespace std; int n, m, i, j, k, a, b, q, A[1010][1010], vis[1010][1010], chk[1010][1010], B[2010]; bool dfs(int a, int b) { if(chk[a][b])return vis[a][b]; chk[a][b]=1; if(a==n&&b==m)return vis[a][b]=1; if(a<n&&A[a+1][b]==0&&dfs(a+1, b))vis[a][b]=1; if(b<m&&A[a][b+1]==0&&dfs(a, b+1))vis[a][b]=1; return vis[a][b]; } void dfs2(int a, int b) { vis[a][b]=0; B[a+b]--; if(a<n&&vis[a+1][b-1]==0&&vis[a+1][b]==1)dfs2(a+1, b); if(b<m&&vis[a-1][b+1]==0&&vis[a][b+1]==1)dfs2(a, b+1); } void dfs3(int a, int b) { vis[a][b]=0; B[a+b]--; if(a>0&&vis[a-1][b+1]==0&&vis[a-1][b]==1)dfs3(a-1, b); if(b>0&&vis[a+1][b-1]==0&&vis[a][b-1]==1)dfs3(a, b-1); } void print() { puts("START"); for(int i=0;i++<n;) { for(int j=0;j++<m;)printf("%d ", vis[i][j]); puts(""); } puts("END"); } main() { for(scanf("%d %d", &n, &m);i++<n;)for(j=0;j++<m;)scanf("%d", &A[i][j]); dfs(1, 1); for(i=0;i++<n;)for(j=0;j++<m;)B[i+j]+=vis[i][j]; for(scanf("%d", &q);q--;) { scanf("%d %d", &a, &b); if(vis[a][b]==0) { puts("1"); A[a][b]=1; } else { if(B[a+b]!=1) { puts("1"); A[a][b]=1; dfs2(a, b); dfs3(a, b); B[a+b]++; } else puts("0"); } } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 1100 KB | Output is correct |
2 | Correct | 2 ms | 1484 KB | Output is correct |
3 | Correct | 3 ms | 1340 KB | Output is correct |
4 | Correct | 4 ms | 1484 KB | Output is correct |
5 | Correct | 3 ms | 1484 KB | Output is correct |
6 | Correct | 4 ms | 1520 KB | Output is correct |
7 | Correct | 4 ms | 1600 KB | Output is correct |
8 | Correct | 4 ms | 1612 KB | Output is correct |
9 | Correct | 4 ms | 1596 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 1100 KB | Output is correct |
2 | Correct | 2 ms | 1484 KB | Output is correct |
3 | Correct | 3 ms | 1340 KB | Output is correct |
4 | Correct | 4 ms | 1484 KB | Output is correct |
5 | Correct | 3 ms | 1484 KB | Output is correct |
6 | Correct | 4 ms | 1520 KB | Output is correct |
7 | Correct | 4 ms | 1600 KB | Output is correct |
8 | Correct | 4 ms | 1612 KB | Output is correct |
9 | Correct | 4 ms | 1596 KB | Output is correct |
10 | Correct | 10 ms | 1336 KB | Output is correct |
11 | Correct | 3 ms | 972 KB | Output is correct |
12 | Correct | 206 ms | 16796 KB | Output is correct |
13 | Correct | 104 ms | 13548 KB | Output is correct |
14 | Correct | 413 ms | 18056 KB | Output is correct |
15 | Correct | 368 ms | 18060 KB | Output is correct |
16 | Correct | 382 ms | 18372 KB | Output is correct |
17 | Correct | 431 ms | 19052 KB | Output is correct |
18 | Correct | 378 ms | 18556 KB | Output is correct |
19 | Correct | 438 ms | 19184 KB | Output is correct |
20 | Correct | 291 ms | 19112 KB | Output is correct |
21 | Correct | 407 ms | 19124 KB | Output is correct |