답안 #361733

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
361733 2021-01-31T12:26:25 Z Bill_00 Furniture (JOI20_furniture) C++14
5 / 100
346 ms 22252 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){
		if(r[fur.ff][fur.ss]==0) 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';
		}
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 768 KB Output is correct
2 Correct 2 ms 876 KB Output is correct
3 Correct 2 ms 876 KB Output is correct
4 Correct 3 ms 1004 KB Output is correct
5 Correct 4 ms 1024 KB Output is correct
6 Correct 4 ms 1004 KB Output is correct
7 Correct 5 ms 1004 KB Output is correct
8 Correct 4 ms 1004 KB Output is correct
9 Correct 4 ms 1004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 768 KB Output is correct
2 Correct 2 ms 876 KB Output is correct
3 Correct 2 ms 876 KB Output is correct
4 Correct 3 ms 1004 KB Output is correct
5 Correct 4 ms 1024 KB Output is correct
6 Correct 4 ms 1004 KB Output is correct
7 Correct 5 ms 1004 KB Output is correct
8 Correct 4 ms 1004 KB Output is correct
9 Correct 4 ms 1004 KB Output is correct
10 Correct 13 ms 1132 KB Output is correct
11 Correct 3 ms 768 KB Output is correct
12 Correct 150 ms 10476 KB Output is correct
13 Correct 66 ms 7912 KB Output is correct
14 Correct 304 ms 15104 KB Output is correct
15 Correct 288 ms 14828 KB Output is correct
16 Correct 315 ms 15748 KB Output is correct
17 Correct 329 ms 16492 KB Output is correct
18 Correct 319 ms 16108 KB Output is correct
19 Runtime error 346 ms 22252 KB Execution killed with signal 11
20 Halted 0 ms 0 KB -