Submission #293950

# Submission time Handle Problem Language Result Execution time Memory
293950 2020-09-08T14:02:18 Z errorgorn Furniture (JOI20_furniture) C++14
100 / 100
380 ms 8568 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,b+1));
	}
	
	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);
		}
	}
	
	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;
		}
		
		/*
		rep(x,1,n+1){
			rep(y,1,m+1) cout<<fblock[x][y]<<" ";
			cout<<endl;
		}
		*/
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 768 KB Output is correct
2 Correct 3 ms 1024 KB Output is correct
3 Correct 2 ms 896 KB Output is correct
4 Correct 4 ms 928 KB Output is correct
5 Correct 5 ms 1024 KB Output is correct
6 Correct 4 ms 1024 KB Output is correct
7 Correct 4 ms 1024 KB Output is correct
8 Correct 4 ms 1024 KB Output is correct
9 Correct 5 ms 1024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 768 KB Output is correct
2 Correct 3 ms 1024 KB Output is correct
3 Correct 2 ms 896 KB Output is correct
4 Correct 4 ms 928 KB Output is correct
5 Correct 5 ms 1024 KB Output is correct
6 Correct 4 ms 1024 KB Output is correct
7 Correct 4 ms 1024 KB Output is correct
8 Correct 4 ms 1024 KB Output is correct
9 Correct 5 ms 1024 KB Output is correct
10 Correct 16 ms 768 KB Output is correct
11 Correct 3 ms 640 KB Output is correct
12 Correct 205 ms 6776 KB Output is correct
13 Correct 81 ms 6008 KB Output is correct
14 Correct 340 ms 7544 KB Output is correct
15 Correct 325 ms 7544 KB Output is correct
16 Correct 335 ms 7776 KB Output is correct
17 Correct 370 ms 8140 KB Output is correct
18 Correct 367 ms 7928 KB Output is correct
19 Correct 365 ms 8220 KB Output is correct
20 Correct 347 ms 8440 KB Output is correct
21 Correct 380 ms 8568 KB Output is correct