제출 #886345

#제출 시각아이디문제언어결과실행 시간메모리
886345stefanneaguFurniture (JOI20_furniture)C++17
100 / 100
226 ms23848 KiB
#include <bits/stdc++.h> using namespace std; const int nmax = 1e3 + 5; int jd[nmax][nmax], ss[nmax][nmax], diag[2 * nmax], n, m; int f[nmax][nmax]; void remo(int i, int j) { if (f[i][j]) return; f[i][j] = 1, diag[i + j]--; if (--jd[i+1][j] == 0) remo(i+1, j); if (--jd[i][j+1] == 0) remo(i, j+1); if (--ss[i-1][j] == 0) remo(i-1, j); if (--ss[i][j-1] == 0) remo(i, j-1); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> m; for (int i = 1; i <= n; f[i][0] = f[i][m+1] = 1, i++) { for (int j = 1; j <= m; f[0][j] = f[n+1][j] = 1, j++) { diag[i+j]++; jd[i+1][j]++, jd[i][j+1]++; ss[i-1][j]++, ss[i][j-1]++; } } for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { int x; cin >> x; if (x) remo(i, j); } } int q; cin >> q; while (q--) { int i, j, ans = 0; cin >> i >> j; if (diag[i + j] != 1 || f[i][j] == 1) remo(i, j), ans = 1; cout << ans << "\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...