#include <bits/stdc++.h>
using namespace std;
// #define DEBUG
#define fi first
#define se second
#define pb push_back
#define sz(v) (int)v.size()
#define all(v) v.begin(),v.end()
#define dbg(x) cerr << #x << " is " << x << "\n";
using ll = long long;
using ii = pair<ll,ll>;
const int N = 1010;
int n, m;
int a[N][N];
bool ok(int r, int c) {
if(a[r][c] != 0) return true;
if(a[r + 1][c - 1] == 3 && a[r - 1][c + 1] == 2) return false;
return true;
}
int dx[] = {-1, 0, 1, 1, 1, 0, -1, -1, -1};
int dy[] = {-1, -1, -1, 0, 1, 1, 1, 0, -1};
void add(int r, int c, int ty) {
if(a[r][c] > 1) return;
assert(ok(r, c));
a[r][c] = ty;
if(a[r - 1][c + 1] == 2 || ty == 2) {
a[r][c] = 2;
add(r - 1, c, 2);
add(r, c + 1, 2);
for(int k = 0; k < 5; k++) {
int tx = r + dx[k], ty = c + dy[k];
if(a[tx][ty] == 1) add(tx, ty, 2);
}
}
else if(a[r + 1][c - 1] == 3 || ty == 3) {
a[r][c] = 3;
add(r, c - 1, 3);
add(r + 1, c, 3);
for(int k = 4; k < 9; k++) {
int tx = r + dx[k], ty = c + dy[k];
if(a[tx][ty] == 1) add(tx, ty, 3);
}
}
}
void show() {
#ifndef DEBUG
return;
#endif
cout << "-----\n";
for(int i = 0; i <= n + 1; i++) {
for(int j = 0; j <= m + 1; j++)
cout << a[i][j] << " ";
cout << endl;
}
cout << "-----\n";
}
int main() {
scanf("%d %d", &n, &m);
for(int i = 1; i <= n; i++) a[i][0] = 3, a[i][m + 1] = 2;
for(int j = 1; j <= m; j++) a[0][j] = 2, a[n + 1][j] = 3;
a[0][m + 1] = 2, a[n + 1][0] = 3;
show();
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
int x; scanf("%d", &x);
if(x == 1) {
add(i, j, 1);
}
}
}
show();
int q; scanf("%d", &q);
while(q--) {
int r, c; scanf("%d %d", &r, &c);
if(!ok(r, c)) puts("0");
else {
puts("1");
add(r, c, 1);
}
show();
}
return 0;
}
Compilation message
furniture.cpp: In function 'int main()':
furniture.cpp:70:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
70 | scanf("%d %d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~~
furniture.cpp:79:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
79 | int x; scanf("%d", &x);
| ~~~~~^~~~~~~~~~
furniture.cpp:86:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
86 | int q; scanf("%d", &q);
| ~~~~~^~~~~~~~~~
furniture.cpp:88:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
88 | int r, c; scanf("%d %d", &r, &c);
| ~~~~~^~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
640 KB |
Output is correct |
2 |
Correct |
2 ms |
768 KB |
Output is correct |
3 |
Correct |
3 ms |
640 KB |
Output is correct |
4 |
Correct |
4 ms |
768 KB |
Output is correct |
5 |
Correct |
4 ms |
768 KB |
Output is correct |
6 |
Correct |
5 ms |
768 KB |
Output is correct |
7 |
Correct |
4 ms |
768 KB |
Output is correct |
8 |
Correct |
4 ms |
768 KB |
Output is correct |
9 |
Correct |
5 ms |
768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
640 KB |
Output is correct |
2 |
Correct |
2 ms |
768 KB |
Output is correct |
3 |
Correct |
3 ms |
640 KB |
Output is correct |
4 |
Correct |
4 ms |
768 KB |
Output is correct |
5 |
Correct |
4 ms |
768 KB |
Output is correct |
6 |
Correct |
5 ms |
768 KB |
Output is correct |
7 |
Correct |
4 ms |
768 KB |
Output is correct |
8 |
Correct |
4 ms |
768 KB |
Output is correct |
9 |
Correct |
5 ms |
768 KB |
Output is correct |
10 |
Correct |
12 ms |
640 KB |
Output is correct |
11 |
Correct |
3 ms |
580 KB |
Output is correct |
12 |
Correct |
214 ms |
4980 KB |
Output is correct |
13 |
Correct |
91 ms |
4096 KB |
Output is correct |
14 |
Correct |
390 ms |
5784 KB |
Output is correct |
15 |
Correct |
383 ms |
5752 KB |
Output is correct |
16 |
Correct |
408 ms |
6008 KB |
Output is correct |
17 |
Correct |
437 ms |
6268 KB |
Output is correct |
18 |
Correct |
402 ms |
6336 KB |
Output is correct |
19 |
Correct |
435 ms |
6304 KB |
Output is correct |
20 |
Correct |
364 ms |
6392 KB |
Output is correct |
21 |
Correct |
469 ms |
6400 KB |
Output is correct |