Submission #886340

#TimeUsernameProblemLanguageResultExecution timeMemory
886340stefanneaguFurniture (JOI20_furniture)C++17
5 / 100
149 ms16820 KiB
#include <bits/stdc++.h> using namespace std; const int nmax = 1e3 + 5; int jd[nmax][nmax], ss[nmax][nmax], diag[nmax], n, m; bool f[nmax][nmax]; bool in(int a, int b) { if(a > n || b > m || min(a, b) < 0) { return 0; } return 1; } void dfs(int i, int j) { if(!in(i, j) || f[i][j] == 1) { return; } f[i][j] = 1; diag[i + j] --; if(--jd[i + 1][j] == 0) { dfs(i + 1, j); } if(--jd[i][j + 1] == 0) { dfs(i, j + 1); } if(--ss[i - 1][j] == 0) { dfs(i - 1, j); } if(--ss[i][j - 1] == 0) { dfs(i, j - 1); } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> m; for(int i = 0; i <= n + 1; i ++) { f[i][0] = 1; f[i][m + 1] = 1; } for(int j = 0; j <= m + 1; j ++) { f[0][j] = 1; f[n + 1][j] = 1; } for(int i = 1; i <= n; i ++) { for(int j = 1; j <= m; 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) { dfs(i, j); //cout << i << " " << j << endl; } } } int q; cin >> q; for(int i = 1; i <= q; i ++) { int a, b; cin >> a >> b; if(f[a][b] == 1 || diag[a + b] != 1) { cout << "1\n"; dfs(a, b); } else { cout << "0\n"; } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...