// #pragma GCC optimize("O3,Ofast,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define MP make_pair
#define pb push_back
#define REP(i,n) for(int i = 0; (i) < (n); (i)++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
void fastio() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
const double EPS = 0.00001;
const int INF = 1e9+500;
const int N = 108;
const int ALPH = 26;
const int LGN = 25;
constexpr int MOD = 1e9+7;
int n,m,q;
vector<vector<int> > gr(N, vector<int>(N, 0));
vector<vector<int> > vis;
bool dfs(int x, int y) {
if(vis[x][y]) return 0;
vis[x][y] = 1;
if(gr[x][y] || x > n || y > m) return 0;
if(x == n && y == m) return 1;
if(dfs(x + 1, y)) return 1;
if(dfs(x, y + 1)) return 1;
return 0;
}
inline void solve() {
cin>>n>>m;
for(int i = 1; i<=n; i++) {
for(int j = 1; j <= m; j++) {
cin >> gr[i][j];
}
}
cin >> q;
for(int i = 1; i<=q; i++) {
int x,y;
cin >> x >> y;
vis.assign(n + 10, vector<int>(m + 10, 0));
gr[x][y] = 1;
if(dfs(1, 1)) {
cout << "1\n";
}
else {
cout << "0\n";
gr[x][y] = 0;
}
}
}
signed main() {
fastio();
int test = 1;
//cin>>test;
while(test--) {
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
344 KB |
Output is correct |
2 |
Correct |
6 ms |
348 KB |
Output is correct |
3 |
Correct |
12 ms |
604 KB |
Output is correct |
4 |
Correct |
26 ms |
604 KB |
Output is correct |
5 |
Correct |
25 ms |
604 KB |
Output is correct |
6 |
Correct |
31 ms |
648 KB |
Output is correct |
7 |
Correct |
35 ms |
604 KB |
Output is correct |
8 |
Correct |
25 ms |
604 KB |
Output is correct |
9 |
Correct |
147 ms |
852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
344 KB |
Output is correct |
2 |
Correct |
6 ms |
348 KB |
Output is correct |
3 |
Correct |
12 ms |
604 KB |
Output is correct |
4 |
Correct |
26 ms |
604 KB |
Output is correct |
5 |
Correct |
25 ms |
604 KB |
Output is correct |
6 |
Correct |
31 ms |
648 KB |
Output is correct |
7 |
Correct |
35 ms |
604 KB |
Output is correct |
8 |
Correct |
25 ms |
604 KB |
Output is correct |
9 |
Correct |
147 ms |
852 KB |
Output is correct |
10 |
Runtime error |
896 ms |
1152 KB |
Execution killed with signal 6 |
11 |
Halted |
0 ms |
0 KB |
- |