Submission #361732

# Submission time Handle Problem Language Result Execution time Memory
361732 2021-01-31T12:23:31 Z Bill_00 Furniture (JOI20_furniture) C++14
0 / 100
2 ms 876 KB
#include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
#define N 1001
typedef long long ll;
using namespace std;
bool r[N][N];
int c[N][N];
int a[N*2];
vector<pair<int,int> >v;
void detect(int x,int y){
	r[x][y]=1;
	a[x+y]--;
	if(r[x+1][y-1]==1){
		if(r[x][y-1]==0){
			detect(x,y-1);
		}
		if(r[x+1][y]==0){
			detect(x+1,y);
		}
	}
	if(r[x-1][y+1]==1){
		if(r[x-1][y]==0){
			detect(x-1,y);
		}
		if(r[x][y+1]==0){
			detect(x,y+1);
		}
	}
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n,m;
	cin >> n >> m;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin >> c[i][j];
			if(c[i][j]==1) v.pb({i,j});
			a[i+j]++;
		}
	}
	for(int i=0;i<=n+1;i++){
		r[i][0]=1;
		r[i][m+1]=1;
	}
	for(int i=0;i<=m+1;i++){
		r[0][i]=1;
		r[n+1][i]=1;
	}
	for(pair<int,int>fur:v){
		detect(fur.ff,fur.ss);
	}
	int q;
	cin >> q;
	while(q--){
		int x,y;
		cin >> x >> y;
		if(r[x][y]==1){
			cout << 1 << '\n';
		}
		else{
			if(a[x+y]>1){
				cout << 1 << '\n';
				detect(x,y);
			}
			else cout << 0 << '\n';
		}
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 748 KB Output is correct
2 Incorrect 2 ms 876 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 748 KB Output is correct
2 Incorrect 2 ms 876 KB Output isn't correct
3 Halted 0 ms 0 KB -