This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
int n, m;
vector <vector<bool>> v, bl;
bool dfs(int x, int y){
if(x < 0 || x >= n || y < 0 || y >= m) return 0;
if(x == n - 1 && y == m - 1) return 1;
if(v[x][y]) return 0;
if(bl[x][y]) return 0;
bl[x][y] = 1;
return dfs(x + 1, y) | dfs(x, y + 1);
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
v = vector<vector<bool>>(n, vector<bool>(m));
for(int i = 0; i < n; i++) for(int j = 0; j < m; j++){
bool bll; cin >> bll;
v[i][j] = bll;
}
int q; cin >> q;
while(q--){
bl = vector<vector<bool>>(n, vector<bool>(m, 0));
int x, y; cin >> x >> y;
x--, y--;
v[x][y] = 1;
if(dfs(0, 0)) cout << "1\n";
else{
v[x][y] = 0;
cout << "0\n";
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |