Submission #732620

# Submission time Handle Problem Language Result Execution time Memory
732620 2023-04-29T06:47:57 Z myrcella Furniture (JOI20_furniture) C++17
100 / 100
442 ms 19796 KB
//by szh
#include<bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pb push_back
#define debug(x) cerr<<#x<<"="<<x<<endl
#define pq priority_queue
#define inf 0x3f
#define rep(i,a,b) for (int i=a;i<(b);i++)
#define MP make_pair
#define SZ(x) (int(x.size()))
#define ll long long
#define mod 1000000007
#define ALL(x) x.begin(),x.end()
void inc(int &a,int b) {a=(a+b)%mod;}
void dec(int &a,int b) {a=(a-b+mod)%mod;}
int lowbit(int x) {return x&(-x);}
ll p0w(ll base,ll p) {ll ret=1;while(p>0){if (p%2ll==1ll) ret=ret*base%mod;base=base*base%mod;p/=2ll;}return ret;}

const int maxn = 1010;

int n,m,Q;
int st[maxn][maxn],ed[maxn][maxn];
vector <pii> pos;

int cnt[maxn*2];

void update(pii x) {
	queue <pii> q;
	if (st[x.fi][x.se]>0) st[x.fi][x.se]=1,q.push(x);
	while (!q.empty()) {
		int r = q.front().fi, c = q.front().se;
		q.pop();
		st[r][c]--;
		if (st[r][c]==0) {
			if (ed[r][c]>0) cnt[r+c]--;
			if (r+1<n and st[r+1][c]>0 and MP(r+1,c)!=MP(n-1,m-1)) q.push({r+1,c});
			if (c+1<m and st[r][c+1]>0 and MP(r,c+1)!=MP(n-1,m-1)) q.push({r,c+1});
		}
	}
	if (ed[x.fi][x.se]>0) ed[x.fi][x.se]=1,q.push(x);
	while (!q.empty()) {
		int r = q.front().fi, c = q.front().se;
		q.pop();
		ed[r][c]--;
		if (ed[r][c]==0) {
			if (st[r][c]>0) cnt[r+c]--;
			if (r>0 and ed[r-1][c]>0 and MP(r-1,c)!=MP(0,0)) q.push({r-1,c});
			if (c>0 and ed[r][c-1]>0 and MP(r,c-1)!=MP(0,0)) q.push({r,c-1});
		}
	}
}

int main() {
//	freopen("input.txt","r",stdin);	
	std::ios::sync_with_stdio(false);cin.tie(0);
	cin>>n>>m;
	rep(i,0,n)
		rep(j,0,m) {
			int x;cin>>x;
			if (x==1) pos.pb({i,j});
			st[i][j] = (i>0) + (j>0);
			ed[i][j] = (i+1<n) + (j+1<m);
			cnt[i+j]++;
		}
	for (auto it:pos) update(it);
	cin>>Q;
	while (Q--) {
		pii x;cin>>x.fi>>x.se;
		x.fi--,x.se--;
//		debug(st[x.fi][x.se]);debug(ed[x.fi][x.se]);
		if (st[x.fi][x.se]*ed[x.fi][x.se]==0 or cnt[x.fi+x.se]>1) cout<<"1\n",update(x);
		else cout<<"0\n";
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 852 KB Output is correct
2 Correct 3 ms 1108 KB Output is correct
3 Correct 3 ms 1140 KB Output is correct
4 Correct 5 ms 1112 KB Output is correct
5 Correct 4 ms 1144 KB Output is correct
6 Correct 5 ms 1128 KB Output is correct
7 Correct 5 ms 1124 KB Output is correct
8 Correct 4 ms 1236 KB Output is correct
9 Correct 5 ms 1236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 852 KB Output is correct
2 Correct 3 ms 1108 KB Output is correct
3 Correct 3 ms 1140 KB Output is correct
4 Correct 5 ms 1112 KB Output is correct
5 Correct 4 ms 1144 KB Output is correct
6 Correct 5 ms 1128 KB Output is correct
7 Correct 5 ms 1124 KB Output is correct
8 Correct 4 ms 1236 KB Output is correct
9 Correct 5 ms 1236 KB Output is correct
10 Correct 12 ms 1244 KB Output is correct
11 Correct 3 ms 724 KB Output is correct
12 Correct 226 ms 13316 KB Output is correct
13 Correct 79 ms 10692 KB Output is correct
14 Correct 379 ms 17760 KB Output is correct
15 Correct 372 ms 17436 KB Output is correct
16 Correct 413 ms 18424 KB Output is correct
17 Correct 442 ms 19304 KB Output is correct
18 Correct 372 ms 18856 KB Output is correct
19 Correct 402 ms 19796 KB Output is correct
20 Correct 378 ms 19732 KB Output is correct
21 Correct 438 ms 19796 KB Output is correct