Submission #742778

#TimeUsernameProblemLanguageResultExecution timeMemory
742778ToniBFurniture (JOI20_furniture)C++17
0 / 100
2 ms724 KiB
#include <bits/stdc++.h> using namespace std; #define X first #define Y second typedef pair<int, int> pii; const int MAXN = 1001; int n, m, q, c[MAXN][MAXN], ans[MAXN * MAXN]; bool flag[MAXN][MAXN], bio[MAXN][MAXN], vis[MAXN][MAXN]; priority_queue<pair<pii, pii> > pq; set<pii> s; int main(){ cin >> n >> m; for(int i = 0; i < n; ++i){ for(int j = 0; j < m; ++j){ cin >> bio[i][j]; if(bio[i][j]) s.insert({i, j}); c[i][j] = n * m + i * m + j; } } cin >> q; for(int i = 0; i < q; ++i){ int x, y; cin >> x >> y, --x, --y; c[x][y] = i; } pq.push({{0, c[0][0]}, {0, 0}}); bio[0][0] = 1; while(!pq.empty()){ int x = pq.top().Y.X, y = pq.top().Y.Y; pq.pop(); if(x != n - 1 && !bio[x + 1][y]){ bio[x + 1][y] = 1; pq.push({{x + y + 1, c[x + 1][y]}, {x + 1, y}}); flag[x + 1][y] = 0; } if(y != m - 1 && !bio[x][y + 1]){ bio[x][y + 1] = 1; pq.push({{x + y + 1, c[x][y + 1]}, {x, y + 1}}); flag[x][y + 1] = 1; } } int i = n - 1, j = m - 1; while(i || j){ if(flag[i][j]) --j; else --i; vis[i][j] = 1; } for(int i = 0; i < n; ++i){ for(int j = 0; j < m; ++j){ if(vis[i][j]) assert(s.find({i, j}) == s.end()); if(c[i][j] < n * m) ans[c[i][j]] = vis[i][j]; } } for(int i = 0; i < q; ++i){ cout << !ans[i] << "\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...