Submission #732580

# Submission time Handle Problem Language Result Execution time Memory
732580 2023-04-29T06:15:58 Z myrcella Furniture (JOI20_furniture) C++17
0 / 100
2 ms 1108 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) 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) 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 856 KB Output is correct
2 Incorrect 2 ms 1108 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 856 KB Output is correct
2 Incorrect 2 ms 1108 KB Output isn't correct
3 Halted 0 ms 0 KB -