#include <bits/stdc++.h>
#define ent '\n'
#define int long long
using namespace std;
typedef long long ll;
const int maxn = 1e6 + 12;
int dp[1050][1050];
int a[1050][1050];
int t[1050][1050];
int ans[maxn];
int u[maxn];
int n, m, k;
int pos(int x, int y){
return (x - 1) * m + y;
}
void solve(int x1, int y1, int x2, int y2){
t[x1][y1] = t[x2][y2] = 1e9;
for(int i=x1;i<=x2;i++){
for(int j=y1;j<=y2;j++){
if(i == x1 && j == y1){
dp[i][j] = 1e9;
continue;
}
dp[i][j] = -1e9;
if(i > x1) dp[i][j] = max(dp[i][j], min(dp[i-1][j], t[i][j]));
if(j > y1) dp[i][j] = max(dp[i][j], min(dp[i][j-1], t[i][j]));
}
}
if(dp[x2][y2] > 1e6) return;
int y = u[dp[x2][y2]] % m;
if(y == 0) y += m;
int x = (u[dp[x2][y2]] - y) / m + 1;
ans[dp[x2][y2]] = 0;
solve(x1, y1, x, y);
solve(x, y, x2, y2);
}
void solve(){
cin >> n >> m;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin >> a[i][j];
t[i][j] = 1e9;
if(a[i][j]){
t[i][j] = 0;
}
}
}
int q;
cin >> q;
for(int i=1;i<=q;i++){
int x, y;
cin >> x >> y;
t[x][y] = i;
u[i] = pos(x, y);
ans[i] = 1;
}
solve(1, 1, n, m);
for(int i=1;i<=q;i++){
cout << ans[i] << ent;
}
}
int32_t main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin >> t;
while(t--){
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1372 KB |
Output is correct |
2 |
Correct |
1 ms |
1628 KB |
Output is correct |
3 |
Correct |
2 ms |
1884 KB |
Output is correct |
4 |
Correct |
2 ms |
1884 KB |
Output is correct |
5 |
Correct |
3 ms |
2088 KB |
Output is correct |
6 |
Correct |
3 ms |
2100 KB |
Output is correct |
7 |
Correct |
3 ms |
2140 KB |
Output is correct |
8 |
Correct |
2 ms |
2140 KB |
Output is correct |
9 |
Correct |
2 ms |
2140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1372 KB |
Output is correct |
2 |
Correct |
1 ms |
1628 KB |
Output is correct |
3 |
Correct |
2 ms |
1884 KB |
Output is correct |
4 |
Correct |
2 ms |
1884 KB |
Output is correct |
5 |
Correct |
3 ms |
2088 KB |
Output is correct |
6 |
Correct |
3 ms |
2100 KB |
Output is correct |
7 |
Correct |
3 ms |
2140 KB |
Output is correct |
8 |
Correct |
2 ms |
2140 KB |
Output is correct |
9 |
Correct |
2 ms |
2140 KB |
Output is correct |
10 |
Correct |
7 ms |
2648 KB |
Output is correct |
11 |
Correct |
2 ms |
1372 KB |
Output is correct |
12 |
Correct |
101 ms |
33872 KB |
Output is correct |
13 |
Correct |
42 ms |
25832 KB |
Output is correct |
14 |
Correct |
164 ms |
45516 KB |
Output is correct |
15 |
Correct |
181 ms |
46416 KB |
Output is correct |
16 |
Correct |
1265 ms |
48896 KB |
Output is correct |
17 |
Correct |
2619 ms |
51532 KB |
Output is correct |
18 |
Correct |
609 ms |
50004 KB |
Output is correct |
19 |
Correct |
180 ms |
52112 KB |
Output is correct |
20 |
Correct |
174 ms |
52308 KB |
Output is correct |
21 |
Correct |
191 ms |
52304 KB |
Output is correct |