Submission #377160

#TimeUsernameProblemLanguageResultExecution timeMemory
377160reymontada61Furniture (JOI20_furniture)C++14
100 / 100
3040 ms16096 KiB
#include <bits/stdc++.h> using namespace std; int n, m; const int MXN = 1005; int grid[MXN][MXN]; void place(int a, int b) { if (grid[a][b] == 0) return; grid[a][b] = 0; { if (grid[a-1][b+1] == 0) { place(a, b+1); place(a-1, b); } } { if (grid[a+1][b-1] == 0) { place(a+1, b); place(a, b-1); } } } int oper(int x, int y) { if (grid[x][y] == 0) { place(x, y); return 1; } int tr = 0; for (int on=1; on<=n; on++) { int ot = x + y - on; if (1 <= ot && ot <= m) { if (grid[on][ot]) tr++; } } if (tr > 1) { place(x, y); return 1; } else { return 0; } } signed main() { cin >> n >> m; for (int i=1; i<=n; i++) { for (int j=1; j<=m; j++) { grid[i][j] = 1; } } int x; for (int i=1; i<=n; i++) { for (int j=1; j<=m; j++) { cin >> x; if (x == 1) { oper(i, j); } } } int q; cin >> q; while (q--) { int x, y; cin >> x >> y; cout << oper(x, y) << endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...