Submission #886343

#TimeUsernameProblemLanguageResultExecution timeMemory
886343stefanneaguFurniture (JOI20_furniture)C++17
5 / 100
175 ms13644 KiB
#include <bits/stdc++.h> using namespace std; const int nmax = 1e3 + 5; int jd[nmax][nmax], ss[nmax][nmax], diag[nmax], n, m; int f[nmax][nmax]; bool in(int a, int b) { if(a > n || b > m || min(a, b) < 0) { return 0; } return 1; } 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 a; cin >> a; if(a == 1) { remo(i, j); //cout << i << " " << j << endl; } } } 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...