# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1031747 | 2024-07-23T06:30:23 Z | 김은성(#10960) | Furniture (JOI20_furniture) | C++17 | 1 ms | 604 KB |
#include <bits/stdc++.h> using namespace std; bool ch[1009][1009], ch2[1009][1009]; int n, m, cnt[2019]; void update(int r, int c){ if(r<=0 || r>n || c<=0 || c>m || !ch[r][c]) return; ch[r][c] = (ch[r-1][c] || ch[r][c-1]) && ch[r][c]; if(ch[r][c]) return; update(r+1, c); update(r, c+1); } void update2(int r, int c){ if(r<=0 || r>n || c<=0 || c>m || !ch2[r][c]) return; cnt[r+c] -= (ch[r][c] && ch2[r][c]); ch2[r][c] = (ch2[r+1][c] || ch2[r][c+1]) && ch2[r][c]; cnt[r+c] += (ch[r][c] && ch2[r][c]); if(ch2[r][c]) return; update2(r-1, c); update2(r, c-1); } int main(){ int i, j, r, c; scanf("%d %d", &n,&m); ch[0][1] = ch[1][0] = ch[n+1][m] = ch[n][m+1] = 1; ch2[0][1] = ch2[1][0] = ch2[n+1][m] = ch2[n][m+1] = 1; for(i=1; i<=n; i++){ for(j=1; j<=m; j++){ int val; scanf("%d", &val); if(!val){ ch[i][j] = ch2[i][j] = 1; } } } for(i=1; i<=n; i++){ for(j=1; j<=m; j++){ ch[i][j] = ((ch[i-1][j] || ch[i][j-1]) && ch[i][j]); } } for(i=n; i>=1; i--){ for(j=m; j>=1; j--){ ch2[i][j] = ((ch2[i+1][j] || ch2[i][j+1]) && ch2[i][j]); if(ch[i][j] && ch2[i][j]){ cnt[i+j]++; } } } int q; scanf("%d", &q); while(q--){ scanf("%d %d", &r, &c); if(!(ch[r][c] && ch2[r][c]) || cnt[r+c] > 1){ printf("1\n"); cnt[r+c] -= (ch[r][c] && ch2[r][c]); ch[r][c] = ch2[r][c] = 0; update(r+1, c), update(r, c+1); update2(r-1, c), update2(r, c-1); } else printf("0\n"); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 600 KB | Output is correct |
2 | Incorrect | 1 ms | 604 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 600 KB | Output is correct |
2 | Incorrect | 1 ms | 604 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |