Submission #707042

#TimeUsernameProblemLanguageResultExecution timeMemory
707042someoneFurniture (JOI20_furniture)C++14
100 / 100
378 ms30380 KiB
#include <bits/stdc++.h> #define int long long #define a second #define b first using namespace std; const int N = 1e3 + 42, INF = 1e18 + 42; bool pos[N][N][2]; int n, m, q, nb[2*N], pre[N][N][2]; int delta[] = {1, -1}; void flood(int i, int j, int id) { if(i >= n || j >= m || i < 0 || j < 0 || !pos[i][j][id]) return; pre[i][j][id]--; if(pre[i][j][id] == 0) { if(pos[i][j][0] && pos[i][j][1]) nb[i + j]--; pos[i][j][id] = false; flood(i + delta[id], j, id); flood(i, j + delta[id], id); } } bool furniture(int i, int j) { if(pos[i][j][0] && pos[i][j][1] && nb[i + j] == 1) return false; pre[i][j][0] = 1; pre[i][j][1] = 1; flood(i, j, 0); flood(i, j, 1); return true; } signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m; for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) { nb[i + j]++; if(i != 0) pre[i][j][0]++; if(j != 0) pre[i][j][0]++; if(i != n-1) pre[i][j][1]++; if(j != m-1) pre[i][j][1]++; pos[i][j][0] = pos[i][j][1] = true; } for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) { int x; cin >> x; if(x) furniture(i, j); } cin >> q; for(int i = 0; i < q; i++) { int x, y; cin >> x >> y; cout << furniture(x-1, y-1) << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...