Submission #387507

#TimeUsernameProblemLanguageResultExecution timeMemory
387507timmyfengFurniture (JOI20_furniture)C++17
100 / 100
363 ms14060 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1000; bool blocked_s[N][N], blocked_t[N][N]; int unblocked[2 * N], n, m; void block_s(int x, int y) { unblocked[x + y] -= !blocked_t[x][y]; blocked_s[x][y] = true; if (x < n - 1 && !blocked_s[x + 1][y] && (y == 0 || blocked_s[x + 1][y - 1])) { block_s(x + 1, y); } if (y < m - 1 && !blocked_s[x][y + 1] && (x == 0 || blocked_s[x - 1][y + 1])) { block_s(x, y + 1); } } void block_t(int x, int y) { unblocked[x + y] -= !blocked_s[x][y]; blocked_t[x][y] = true; if (x > 0 && !blocked_t[x - 1][y] && (y == m - 1 || blocked_t[x - 1][y + 1])) { block_t(x - 1, y); } if (y > 0 && !blocked_t[x][y - 1] && (x == n - 1 || blocked_t[x + 1][y - 1])) { block_t(x, y - 1); } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> m; for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { int c; cin >> c; if (c == 1) { if (!blocked_s[i][j]) { block_s(i, j); } if (!blocked_t[i][j]) { block_t(i, j); } } ++unblocked[i + j]; } } int q; cin >> q; while (q--) { int x, y; cin >> x >> y; --x, --y; if (blocked_s[x][y] || blocked_t[x][y]) { cout << 1 << "\n"; } else if (unblocked[x + y] > 1) { cout << 1 << "\n"; block_s(x, y); block_t(x, y); } else { cout << 0 << "\n"; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...