Submission #904652

# Submission time Handle Problem Language Result Execution time Memory
904652 2024-01-12T07:00:16 Z dsyz Furniture (JOI20_furniture) C++17
100 / 100
237 ms 13036 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MAXN (1005)
ll N,M;
ll cnt[2 * MAXN];
bool R[MAXN][MAXN];
void del(ll i, ll j){
    if(R[i][j] == 0 || cnt[i + j] == 1) return;
    cnt[i + j]--;
    R[i][j] = 0;
    if(i + 1 < N && (j == 0 || R[i + 1][j - 1] == 0)) del(i + 1,j);
    if(i - 1 >= 0 && (j == M - 1 || R[i - 1][j + 1] == 0)) del(i - 1,j);
    if(j + 1 < M && (i == 0 || R[i - 1][j + 1] == 0)) del(i,j + 1);
    if(j - 1 >= 0 && (i == N - 1 || R[i + 1][j - 1] == 0)) del(i,j - 1);
}
int main() {
	ios_base::sync_with_stdio(false);cin.tie(0);
	cin>>N>>M;
	for(ll i = 0;i < N;i++){
		for(ll j = 0;j < M;j++){
			R[i][j] = 1;
			cnt[i + j]++;
		}
	}
	for(ll i = 0;i < N;i++){
		for(ll j = 0;j < M;j++){
			ll a;
			cin>>a;
			if(a == 1){
				del(i,j);
			}
		}
	}
	ll Q;
	cin>>Q;
	for(ll i = 0;i < Q;i++){
		ll A,B;
		cin>>A>>B;
		A--, B--;
		del(A,B);
		if(R[A][B]){
			cout<<0<<'\n';
		}else{
			cout<<1<<'\n';
		}
	}
}
# 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 2 ms 604 KB Output is correct
4 Correct 3 ms 604 KB Output is correct
5 Correct 3 ms 604 KB Output is correct
6 Correct 3 ms 604 KB Output is correct
7 Correct 3 ms 604 KB Output is correct
8 Correct 3 ms 604 KB Output is correct
9 Correct 3 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 2 ms 604 KB Output is correct
4 Correct 3 ms 604 KB Output is correct
5 Correct 3 ms 604 KB Output is correct
6 Correct 3 ms 604 KB Output is correct
7 Correct 3 ms 604 KB Output is correct
8 Correct 3 ms 604 KB Output is correct
9 Correct 3 ms 604 KB Output is correct
10 Correct 7 ms 860 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 110 ms 5940 KB Output is correct
13 Correct 38 ms 3288 KB Output is correct
14 Correct 185 ms 10780 KB Output is correct
15 Correct 180 ms 11208 KB Output is correct
16 Correct 198 ms 12112 KB Output is correct
17 Correct 236 ms 12628 KB Output is correct
18 Correct 205 ms 12376 KB Output is correct
19 Correct 209 ms 12992 KB Output is correct
20 Correct 237 ms 13036 KB Output is correct
21 Correct 219 ms 13028 KB Output is correct