이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define mp make_pair
#define X first
#define Y second
using namespace std;
typedef long long ll;
typedef pair <int, int> ii;
const int N = 1002;
const int dx[8] = {-1, 0, 0, 1};
const int dy[8] = {0, -1, 1, 0};
int m, n, q, a[N][N], imp[N][N], cnt[2 * N];
bool d[N][N];
void readInput(){
cin >> m >> n;
for(int i = 1; i <= m; i++)
for(int j = 1; j <= n; j++)
cin >> a[i][j];
}
void update(int x, int y){
if (!imp[x][y])
return;
imp[x][y] = 0;
cnt[x + y]--;
if (!imp[x - 1][y + 1]){
update(x - 1, y);
update(x, y + 1);
}
if (!imp[x + 1][y - 1]){
update(x, y - 1);
update(x + 1, y);
}
}
void solve(){
for(int i = 1; i <= m; i++)
for(int j = 1; j <= n; j++)
imp[i][j] = 1;
memset(d, 0, sizeof(d));
d[1][1] = 1;
for(int i = 1; i <= m; i++)
for(int j = 1; j <= n; j++){
d[i][j] |= d[i - 1][j];
d[i][j] |= d[i][j - 1];
if (a[i][j])
d[i][j] = 0;
imp[i][j] &= d[i][j];
}
memset(d, 0, sizeof(d));
d[m][n] = 1;
for(int i = m; i >= 1; i--)
for(int j = n; j >= 1; j--){
d[i][j] |= d[i + 1][j];
d[i][j] |= d[i][j + 1];
if (a[i][j])
d[i][j] = 0;
imp[i][j] &= d[i][j];
}
for(int i = 1; i <= m; i++)
for(int j = 1; j <= n; j++)
if (imp[i][j])
cnt[i + j]++;
cin >> q;
while (q--){
int x, y;
cin >> x >> y;
if (!imp[x][y]){
cout << "1\n";
continue;
}
if (cnt[x + y] == 1){
cout << "0\n";
continue;
}
update(x, y);
cout << "1\n";
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
readInput();
solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |