# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1210091 | nguyn | Furniture (JOI20_furniture) | C++20 | 1 ms | 836 KiB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second
#define pb push_back
#define pii pair<int,int>
const int N = 1e3 + 5;
int vis[N][N], n, m;
int d[2 * N];
void block(int x, int y) {
d[x + y]--;
vis[x][y] = 1;
if (vis[x + 1][y - 1] && !vis[x + 1][y]) block(x + 1, y);
if (vis[x + 1][y - 1] && !vis[x][y - 1]) block(x, y - 1);
if (vis[x - 1][y + 1] && !vis[x - 1][y]) block(x - 1, y);
if (vis[x - 1][y + 1] && !vis[x][y + 1]) block(x, y + 1);
}
signed main(){
ios_base::sync_with_stdio(false) ;
cin.tie(0) ; cout.tie(0) ;
if (fopen("INP.INP" ,"r")) {
freopen("INP.INP" ,"r" , stdin) ;
freopen("OUT.OUT" , "w" , stdout) ;
}
cin >> n >> m;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
d[i + j]++;
vis[i][j] = 0;
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
int c;
cin >> c;
if (c && !vis[i][j]) {
block(i, j);
}
}
}
int q;
cin >> q;
while(q--) {
int x, y;
cin >> x >> y;
if (vis[x][y]) {
cout << 1 << '\n';
}
else if (d[x + y] == 1) {
cout << 0 << '\n';
}
else {
cout << 1 << '\n';
block(x, y);
}
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |