이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |