Submission #306804

#TimeUsernameProblemLanguageResultExecution timeMemory
306804MrDominoFurniture (JOI20_furniture)C++14
0 / 100
18 ms1408 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; const int N = 2000 + 7; int n; int m; int a[N][N]; bool down[N][N]; bool up[N][N]; bool on[N][N]; int cnt[2 * N]; void init() { for (int i = 1; i <= n + m; i++) { cnt[i] = 0; } down[n + 1][m] = 1; up[1][0] = 1; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (a[i][j] == 0) { up[i][j] = up[i - 1][j] | up[i][j - 1]; } else { up[i][j] = 0; } } } for (int i = n; i >= 1; i--) { for (int j = m; j >= 1; j--) { if (a[i][j] == 0) { down[i][j] = down[i + 1][j] | down[i][j + 1]; } else { down[i][j] = 0; } } } for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (up[i][j] && down[i][j]) { cnt[i + j]++; on[i][j] = 1; } } } } int main() { ios::sync_with_stdio(0); cin.tie(0); ///freopen ("input", "r", stdin); cin >> n >> m; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { cin >> a[i][j]; } } init(); int q; cin >> q; while (q--) { int r, c; cin >> r >> c; if (on[r][c] == 0) { cout << "1\n"; continue; } if (cnt[r + c] == 1) { cout << "0\n"; continue; } cout << "1\n"; a[r][c] = 1; init(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...