# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
301087 | 2020-09-17T16:21:06 Z | milisav | Furniture (JOI20_furniture) | C++14 | 560 ms | 19192 KB |
#include<bits/stdc++.h> #pragma GCC optimize("O3") #define maxn 1010 using namespace std; bool p1[maxn][maxn]; bool p2[maxn][maxn]; bool tp[maxn][maxn]; int tc[2*maxn]; int n,m; int c[maxn][maxn]; int q; int x,y; void rec1(int u,int v) { if(!p1[u][v]) return; if(c[u][v]==0) { if(u==1 && v==1) p1[u][v]=true; else { if(u==1) p1[u][v]=p1[u][v-1]; else { if(v==1) p1[u][v]=p1[u-1][v]; else p1[u][v]=p1[u-1][v]||p1[u][v-1]; } } } else p1[u][v]=false; if(p1[u][v]) return; if(p2[u][v]) { tp[u][v]=false; tc[u+v]--; } if(u<n) rec1(u+1,v); if(v<m) rec1(u,v+1); } void rec2(int u,int v) { if(!p2[u][v]) return; if(c[u][v]==0) { if(u==n && v==m) p2[u][v]=true; else { if(u==n) p2[u][v]=p2[u][v+1]; else { if(v==m) p2[u][v]=p2[u+1][v]; else p2[u][v]=p2[u+1][v]||p2[u][v+1]; } } } else p2[u][v]=false; if(p2[u][v]) return; if(p1[u][v]) { tp[u][v]=false; tc[u+v]--; } if(u>1) rec2(u-1,v); if(v>1) rec2(u,v-1); } int main() { scanf("%d %d",&n,&m); for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { scanf("%d",&c[i][j]); } } for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { if(c[i][j]==1) continue; if(i==1 && j==1) { p1[i][j]=true; continue; } if(i==1) p1[i][j]=p1[i][j-1]; else { if(j==1) p1[i][j]=p1[i-1][j]; else p1[i][j]=p1[i][j-1]||p1[i-1][j]; } } } for(int i=n;i>=1;i--) { for(int j=m;j>=1;j--) { if(c[i][j]==1) continue; if(i==n && j==m) { p2[i][j]=true; continue; } if(i==n) p2[i][j]=p2[i][j+1]; else { if(j==m) p2[i][j]=p2[i+1][j]; else p2[i][j]=p2[i][j+1]||p2[i+1][j]; } } } for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { if(p1[i][j] && p2[i][j]) { tp[i][j]=true; tc[i+j]++; } } } scanf("%d",&q); while(q--) { scanf("%d %d",&x,&y); if(tp[x][y] && tc[x+y]==1) printf("0\n"); else { printf("1\n"); c[x][y]=1; if(p1[x][y]) rec1(x,y); if(p2[x][y]) rec2(x,y); } } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 896 KB | Output is correct |
2 | Correct | 2 ms | 1024 KB | Output is correct |
3 | Correct | 3 ms | 1024 KB | Output is correct |
4 | Correct | 4 ms | 1024 KB | Output is correct |
5 | Correct | 5 ms | 1152 KB | Output is correct |
6 | Correct | 5 ms | 1152 KB | Output is correct |
7 | Correct | 6 ms | 1152 KB | Output is correct |
8 | Correct | 5 ms | 1152 KB | Output is correct |
9 | Correct | 5 ms | 1152 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 896 KB | Output is correct |
2 | Correct | 2 ms | 1024 KB | Output is correct |
3 | Correct | 3 ms | 1024 KB | Output is correct |
4 | Correct | 4 ms | 1024 KB | Output is correct |
5 | Correct | 5 ms | 1152 KB | Output is correct |
6 | Correct | 5 ms | 1152 KB | Output is correct |
7 | Correct | 6 ms | 1152 KB | Output is correct |
8 | Correct | 5 ms | 1152 KB | Output is correct |
9 | Correct | 5 ms | 1152 KB | Output is correct |
10 | Correct | 14 ms | 1024 KB | Output is correct |
11 | Correct | 5 ms | 768 KB | Output is correct |
12 | Correct | 271 ms | 11896 KB | Output is correct |
13 | Correct | 100 ms | 8824 KB | Output is correct |
14 | Correct | 484 ms | 16376 KB | Output is correct |
15 | Correct | 500 ms | 16544 KB | Output is correct |
16 | Correct | 532 ms | 17528 KB | Output is correct |
17 | Correct | 554 ms | 18576 KB | Output is correct |
18 | Correct | 508 ms | 17912 KB | Output is correct |
19 | Correct | 560 ms | 18808 KB | Output is correct |
20 | Correct | 404 ms | 19192 KB | Output is correct |
21 | Correct | 540 ms | 18936 KB | Output is correct |