Submission #349027

#TimeUsernameProblemLanguageResultExecution timeMemory
349027apostoldaniel854Furniture (JOI20_furniture)C++14
100 / 100
303 ms13036 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back const int MAX_N = 1000; bool blocked[1 + MAX_N + 1][1 + MAX_N + 1]; int diag[1 + 2 * MAX_N]; int n, m; void go_stupid (int x, int y) { if (x >= 1 && x <= n && y >= 1 && y <= m) { if (not blocked[x][y]) { blocked[x][y] = true; diag[x + y]--; if (x == 1 || y == m || blocked[x - 1][y + 1]) { go_stupid (x, y + 1); go_stupid (x - 1, y); } if (x == n || y == 1 || blocked[x + 1][y - 1]) { go_stupid (x, y - 1); go_stupid (x + 1, y); } } } } int main() { ios::sync_with_stdio (false); cin.tie (0); cout.tie (0); cin >> n >> m; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) diag[i + j]++; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) { int x; cin >> x; if (x) go_stupid (i, j); } int q; cin >> q; while (q--) { int x, y; cin >> x >> y; if (blocked[x][y]) cout << "1\n"; else if (diag[x + y] == 1) cout << "0\n"; else { cout << "1\n"; go_stupid (x, y); } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...