#include<bits/stdc++.h>
#define taskname "A"
using namespace std;
int n, m;
namespace sub1{
void solve(){
vector<vector<bool>>c(n, vector<bool>(m, false));
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
int x;
cin >> x;
if(x == 1){
c[i][j] = true;
}
}
}
int q;
cin >> q;
for(int _ = 0; _ < q; _++){
int x, y;
cin >> x >> y;
c[--x][--y] = true;
vector<vector<bool>>vis(n, vector<bool>(m, false));
auto dfs = [&] (auto&& self, int x, int y){
if(x < 0 || x == n || y < 0 || y == m || vis[x][y] || c[x][y]){
return;
}
vis[x][y] = true;
self(self, x - 1, y);
self(self, x + 1, y);
self(self, x, y - 1);
self(self, x, y + 1);
};
dfs(dfs, 0, 0);
cout << vis[n - 1][m - 1] << "\n";
if(!vis[n - 1][m - 1]){
c[x][y] = false;
}
}
}
}
namespace sub2{
void solve(){
}
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if(fopen(taskname".inp", "r")){
freopen(taskname".inp", "r", stdin);
}
cin >> n >> m;
if(n <= 100 && m <= 100){
sub1::solve();
}
else{
sub2::solve();
}
}
Compilation message (stderr)
furniture.cpp: In function 'int main()':
furniture.cpp:50:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
50 | freopen(taskname".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |