#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
vector<pair<int, int>> dir{{1, 0}, {0, 1}};
void test_case() {
int n, m;
cin >> n >> m;
vector<vector<int>> s(n, vector<int>(m));
for(int j = 0;j < n;++j) for(int i = 0;i < m;++i) cin >> s[j][i];
int q;
cin >> q;
vector<int> res(q+1, 1);
vector<vector<int>> ps(n, vector<int>(m, q+1));
for(int i = 0;i < n;++i) for(int j = 0;j < m;++j) if(s[i][j] == 1) ps[i][j] = 0;
for(int j = 1;j <= q;++j) {
int x, y;
cin >> x >> y;
--x;--y;
ps[x][y] = j;
}
vector<vector<bool>> vis(n, vector<bool>(m, false));
vector<vector<pair<int, int>>> par(n, vector<pair<int, int>>(m, {-1, -1}));
function<void(int, int)> dfs = [&](int i, int j) {
vis[i][j] = 1;
vector<array<int, 3>> candi;
for(auto d1 : dir) {
int x = d1.first + i, y = d1.second + j;
if(x < n && y < m && !vis[x][y] && ps[x][y]) {
candi.push_back({ps[x][y], x, y});
}
}
if(candi.size() > 1 && candi[0][0] < candi[1][0])
swap(candi[0], candi[1]);
for(auto [d, a, b] : candi) {
par[a][b] = {i, j};
dfs(a, b);
}
};
dfs(0, 0);
int x = n - 1, y = m - 1;
int len = 1;
while(len != n + m -1) {
assert(par[x][y].first != -1);
if(ps[x][y] > 0 && ps[x][y] <= q) res[ps[x][y]] = 0;
auto r = par[x][y];
x = r.first, y = r.second;
len += 1;
}
for(int j = 1;j <= q;++j) cout << res[j] << '\n';
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int tt;
tt = 1;
//cin >> tt;
while(tt--) {
test_case();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |