Submission #1095847

#TimeUsernameProblemLanguageResultExecution timeMemory
1095847_8_8_Furniture (JOI20_furniture)C++17
0 / 100
1 ms860 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1e3 + 12, MOD = (int)1e9 + 7; int n, m, a[N][N], c[N * 2]; bool ok(int x, int y) { return min(x, y) >= 0 && x <= n + 1 && y <= m + 1 && a[x][y]; } void make(int x, int y) { // cout << x << ' ' << y << '\n'; if(a[x][y]) return; a[x][y] = 1; c[x + y]--; if(a[x + 1][y - 1]) { if(y - 1 >= 1) make(x, y - 1); if(x + 1 <= n) make(x + 1, y); } if(a[x - 1][y + 1]) { if(x - 1 >= 1) make(x - 1, y); if(y + 1 <= n) make(x, y + 1); } } void test() { cin >> n >> m; for(int i = 0; i <= m + 1; i++) { a[0][i] = a[n + 1][i] = 1; } for(int i = 0; i <= n + 1; i++) { a[i][0] = a[i][m + 1] = 1; } a[0][0] = a[n + 1][m + 1] = a[0][m + 1] = a[n + 1][0] = 0; for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) { c[i + j]++; } } for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) { cin >> a[i][j]; } } for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) { if(a[i][j]) { a[i][j] = 0; make(i, j); } } } // return; int q; cin >> q; while(q--) { int x, y; cin >> x >> y; if(a[x][y]) { cout << 1 << '\n'; } else { if(c[x + y] > 1) { cout << 1 << '\n'; make(x, y); } else { cout << 0 << '\n'; } } } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int t = 1; // cin >> t; while(t--) test(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...