Submission #297788

#TimeUsernameProblemLanguageResultExecution timeMemory
297788eriksuenderhaufFurniture (JOI20_furniture)C++17
100 / 100
396 ms23928 KiB
#include <bits/stdc++.h> using namespace std; int in[1005][1005], out[1005][1005], a[1005][1005], cnt[2005]; void remove(int i, int j) { if (a[i][j]) return; a[i][j] = 1, cnt[i + j]--; if (--in[i+1][j] == 0) remove(i+1, j); if (--in[i][j+1] == 0) remove(i, j+1); if (--out[i-1][j] == 0) remove(i-1, j); if (--out[i][j-1] == 0) remove(i, j-1); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; for (int i = 1; i <= n; a[i][0] = a[i][m+1] = 1, i++) { for (int j = 1; j <= m; a[0][j] = a[n+1][j] = 1, j++) { cnt[i+j]++; in[i+1][j]++, in[i][j+1]++; out[i-1][j]++, out[i][j-1]++; } } for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { int x; cin >> x; if (x) remove(i, j); } } int q; cin >> q; while (q--) { int i, j, ans = 0; cin >> i >> j; if (cnt[i + j] != 1 || a[i][j] == 1) remove(i, j), ans = 1; cout << ans << "\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...