#include<bits/stdc++.h>
#ifdef LOCAL
#include "Essentials/algo/debug.h"
#else
#define debug(...) 69
#define debugArr(...) 69
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int N = 1e3 + 23;
const ll inf = 1e18;
#define F first
#define S second
#define pb push_back
#define kill(x) cout<<x<<endl, exit(0);
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define lc (v << 1)
#define rc ((v<<1) |1)
int n,m;
bool ok[N][N];
int cnt[N*4];
bool check(int i,int j) {
if(!ok[i][j]) return false;
if((i == n && j == m) || (i == 1 && j == 1)) return false;
if((!ok[i-1][j] && !ok[i][j-1]) || (!ok[i+1][j] && !ok[i][j+1])) {
debug(i,j,!ok[i-1][j],!ok[i][j-1],!ok[i+1][j],!ok[i][j+1]);
return true;
} else {
return false;
}
}
int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
void dfs(int x,int y) {
ok[x][y] = 0;
debug(x,y);
cnt[x+y] --;
for(int id= 0 ; id <4; id ++) {
int x2 = x + dx[id],y2 = y + dy[id];
if(check(x2,y2)) {
dfs(x2,y2);
}
}
}
bool qry(int x,int y) {
debug(x,y,ok[x][y]);
if(!ok[x][y]) return true;
if(cnt[x+y] == 1) return false;
for(int i = 1; i <= n ; i ++) debugArr(ok[i],m+2);
dfs(x,y);
for(int i = 1; i <= n ; i ++) debugArr(ok[i],m+2);
return true;
}
int32_t main() {
cin.tie(nullptr)->sync_with_stdio(false);
cin>>n>>m;
for(int i =1; i <= n; i++) for(int j = 1; j <= m ; j ++) {
ok[i][j] = 1;
cnt[i+j] ++;
}
for(int i = 1;i <= n ;i ++) for(int j = 1; j<= m ; j ++) {
int x; cin>>x;
if(x) {
qry(i,j);
}
}
int q; cin>>q;
while(q--) {
int x,y; cin>>x>>y;
cout<<qry(x,y) << '\n';
}
return 0;
}
// Jumpsuit, Jumpsuit cover me!
// Jumpsuit, Jumpsuit cover me!
Compilation message
furniture.cpp: In function 'bool check(int, int)':
furniture.cpp:5:23: warning: statement has no effect [-Wunused-value]
5 | #define debug(...) 69
| ^~
furniture.cpp:34:3: note: in expansion of macro 'debug'
34 | debug(i,j,!ok[i-1][j],!ok[i][j-1],!ok[i+1][j],!ok[i][j+1]);
| ^~~~~
furniture.cpp: In function 'void dfs(int, int)':
furniture.cpp:5:23: warning: statement has no effect [-Wunused-value]
5 | #define debug(...) 69
| ^~
furniture.cpp:45:2: note: in expansion of macro 'debug'
45 | debug(x,y);
| ^~~~~
furniture.cpp: In function 'bool qry(int, int)':
furniture.cpp:5:23: warning: statement has no effect [-Wunused-value]
5 | #define debug(...) 69
| ^~
furniture.cpp:56:2: note: in expansion of macro 'debug'
56 | debug(x,y,ok[x][y]);
| ^~~~~
furniture.cpp:6:24: warning: statement has no effect [-Wunused-value]
6 | #define debugArr(...) 69
| ^~
furniture.cpp:59:32: note: in expansion of macro 'debugArr'
59 | for(int i = 1; i <= n ; i ++) debugArr(ok[i],m+2);
| ^~~~~~~~
furniture.cpp:6:24: warning: statement has no effect [-Wunused-value]
6 | #define debugArr(...) 69
| ^~
furniture.cpp:61:32: note: in expansion of macro 'debugArr'
61 | for(int i = 1; i <= n ; i ++) debugArr(ok[i],m+2);
| ^~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
608 KB |
Output is correct |
4 |
Correct |
2 ms |
604 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
2 ms |
656 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
604 KB |
Output is correct |
9 |
Correct |
2 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
608 KB |
Output is correct |
4 |
Correct |
2 ms |
604 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
2 ms |
656 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
604 KB |
Output is correct |
9 |
Correct |
2 ms |
604 KB |
Output is correct |
10 |
Correct |
6 ms |
860 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
98 ms |
6112 KB |
Output is correct |
13 |
Correct |
37 ms |
3160 KB |
Output is correct |
14 |
Correct |
203 ms |
10836 KB |
Output is correct |
15 |
Correct |
179 ms |
11092 KB |
Output is correct |
16 |
Correct |
165 ms |
11940 KB |
Output is correct |
17 |
Correct |
180 ms |
12588 KB |
Output is correct |
18 |
Correct |
170 ms |
12368 KB |
Output is correct |
19 |
Correct |
188 ms |
12884 KB |
Output is correct |
20 |
Correct |
169 ms |
12976 KB |
Output is correct |
21 |
Correct |
183 ms |
12848 KB |
Output is correct |