#include<bits/stdc++.h>
#define sherina ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define int long long
#define INF 1e18
#define endl '\n'
using namespace std;
int n , m , c[1005][1005] , q , x , y, diag[2005];
void rec(int x , int y){
if(c[x][y]) return;
//cout << x << " " << y << endl;
diag[x + y]--;
c[x][y] = 1;
if(c[x + 1][y - 1]){
rec(x , y - 1);
rec(x + 1 , y);
}
if(c[x - 1][y + 1]){
//cout << x -1 << " " << y + 1<< endl;
rec(x - 1 , y);
rec(x , y + 1);
}
}
signed main(){
cin >> n >> m;
for(int i = 0 ; i <= n + 1 ; i++){
c[i][0] = 1;
c[i][m + 1] = 1;
}
for(int i = 0 ; i <= m + 1 ; i++){
c[0][i] = 1;
c[n + 1][i] = 1;
}
// for(int i = 0; i <= n + 1; i++){
// for(int j = 0; j <= m + 1; j++){
// cout << c[i][j] << ' ';
// }
// cout << '\n';
// }
for(int i = 1 ; i <= n ; i++){
for(int j = 1 ; j <= m ; j++){
int x;
cin >> x;
diag[i + j]++;
if(x){
rec(i , j);
}
}
}
//cout << diag[5] << endl;
cin >> q;
while(q--){
cin >> x >> y;
if(c[x][y]){
cout << "1" << endl;
}
else if(diag[x + y] == 1){
cout << "0" << endl;
}
else{
cout <<"1" << endl;
rec(x , y);
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
596 KB |
Output is correct |
2 |
Correct |
6 ms |
724 KB |
Output is correct |
3 |
Correct |
8 ms |
804 KB |
Output is correct |
4 |
Correct |
15 ms |
864 KB |
Output is correct |
5 |
Correct |
13 ms |
892 KB |
Output is correct |
6 |
Correct |
17 ms |
956 KB |
Output is correct |
7 |
Correct |
14 ms |
852 KB |
Output is correct |
8 |
Correct |
19 ms |
832 KB |
Output is correct |
9 |
Correct |
15 ms |
852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
596 KB |
Output is correct |
2 |
Correct |
6 ms |
724 KB |
Output is correct |
3 |
Correct |
8 ms |
804 KB |
Output is correct |
4 |
Correct |
15 ms |
864 KB |
Output is correct |
5 |
Correct |
13 ms |
892 KB |
Output is correct |
6 |
Correct |
17 ms |
956 KB |
Output is correct |
7 |
Correct |
14 ms |
852 KB |
Output is correct |
8 |
Correct |
19 ms |
832 KB |
Output is correct |
9 |
Correct |
15 ms |
852 KB |
Output is correct |
10 |
Correct |
38 ms |
1140 KB |
Output is correct |
11 |
Correct |
9 ms |
576 KB |
Output is correct |
12 |
Correct |
527 ms |
12768 KB |
Output is correct |
13 |
Correct |
125 ms |
9644 KB |
Output is correct |
14 |
Correct |
1248 ms |
17216 KB |
Output is correct |
15 |
Correct |
1257 ms |
17464 KB |
Output is correct |
16 |
Correct |
1372 ms |
18488 KB |
Output is correct |
17 |
Correct |
1453 ms |
19456 KB |
Output is correct |
18 |
Correct |
1403 ms |
18836 KB |
Output is correct |
19 |
Correct |
1493 ms |
19704 KB |
Output is correct |
20 |
Correct |
1470 ms |
19800 KB |
Output is correct |
21 |
Correct |
1501 ms |
19736 KB |
Output is correct |