Submission #293944

# Submission time Handle Problem Language Result Execution time Memory
293944 2020-09-08T13:57:31 Z errorgorn Furniture (JOI20_furniture) C++14
0 / 100
3 ms 1024 KB
//雪花飄飄北風嘯嘯
//天地一片蒼茫

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl

#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
//change less to less_equal for non distinct pbds, but erase will bug

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

int n,m,q;
int c[1005][1005];
bool fblock[1005][1005];
bool bblock[1005][1005];

int cnt[2005];

queue<ii> fq,bq;

void proc(int i,int j){
	//cout<<"debug: "<<i<<" "<<j<<endl;
	if (!fblock[i][j]) fq.push(ii(i,j));
	if (!bblock[i][j]) bq.push(ii(i,j));
	
	int a,b;
	while (!fq.empty()){
		tie(a,b)=fq.front(),fq.pop();
		//cout<<"f: "<<a<<" "<<b<<endl;
		fblock[a][b]=true;
		if (!bblock[a][b]) cnt[a+b]--;
		
		if (!fblock[a+1][b] && fblock[a+1][b-1]) fq.push(ii(a+1,b));
		if (!fblock[a][b+1] && fblock[a-1][b+1]) fq.push(ii(a+1,b));
	}
	
	while (!bq.empty()){
		tie(a,b)=bq.front(),bq.pop();
		//cout<<"b: "<<a<<" "<<b<<endl;
		bblock[a][b]=true;
		if (!fblock[a][b]) cnt[a+b]--;
		
		if (!bblock[a-1][b] && bblock[a-1][b+1]) bq.push(ii(a-1,b));
		if (!bblock[a][b-1] && bblock[a+1][b-1]) bq.push(ii(a,b-1));
	}
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin.exceptions(ios::badbit | ios::failbit);
	
	cin>>n>>m;
	
	rep(x,1,n+1) rep(y,1,m+1) cnt[x+y]++;
	
	rep(x,1,m+1) fblock[0][x]=fblock[n+1][x]=bblock[0][x]=bblock[n+1][x]=true;
	rep(x,1,n+1) fblock[x][0]=fblock[x][m+1]=bblock[x][0]=bblock[x][m+1]=true;
	
	rep(x,1,n+1){
		rep(y,1,m+1){
			cin>>c[x][y];
			if (c[x][y]) proc(x,y);
		}
	}
	
	//rep(x,2,n+m+2) cout<<cnt[x]<<" "; cout<<endl;
	
	cin>>q;
	
	int a,b;
	while (q--){
		cin>>a>>b;
		
		if (fblock[a][b] || bblock[a][b] || cnt[a+b]>1){
			cout<<1<<endl;
			proc(a,b);
		}
		else{
			cout<<0<<endl;
		}
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 768 KB Output is correct
2 Incorrect 3 ms 1024 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 768 KB Output is correct
2 Incorrect 3 ms 1024 KB Output isn't correct
3 Halted 0 ms 0 KB -