답안 #331541

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
331541 2020-11-28T20:56:55 Z GioChkhaidze Furniture (JOI20_furniture) C++14
100 / 100
3016 ms 13144 KB
#include <bits/stdc++.h>
using namespace std;

const int N=1003;

bool f[N][N];
int a,n,m,q,x,y,d[2*N];

void Dfs(int a,int b);
void M(int a,int b);

void Dfs(int x,int y) {
	if (!f[x-1][y+1]) {
		M(x,y+1);
		M(x-1,y);
	}
	
	if (!f[x+1][y-1]) {
		M(x,y-1);
		M(x+1,y);
	}
} 

void M(int x,int y) {
	if (f[x][y]) {
		f[x][y]=false;
		--d[x+y];
		Dfs(x,y);
	}
}

main () {
	cin>>n>>m;
	
	for (int i=1; i<=n; i++)
		for (int j=1; j<=m; j++)
			f[i][j]=true,d[i+j]++;
	
	for (int i=1; i<=n; i++) {
		for (int j=1; j<=m; j++) {
			cin>>a;
			if (a && f[i][j]) 
				M(i,j);
		}		
	}
	
	cin>>q;
	for (int i=1; i<=q; i++) {
		cin>>x>>y;
		
		if (!f[x][y]) {
			cout<<1<<"\n";
			continue;
		}
		
		if (d[x+y]==1) {
			cout<<0<<"\n";
			continue;
		}
		
		cout<<1<<"\n";
		M(x,y);
	}
}

Compilation message

furniture.cpp:33:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   33 | main () {
      |       ^
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 364 KB Output is correct
2 Correct 10 ms 492 KB Output is correct
3 Correct 14 ms 492 KB Output is correct
4 Correct 23 ms 620 KB Output is correct
5 Correct 28 ms 492 KB Output is correct
6 Correct 29 ms 524 KB Output is correct
7 Correct 28 ms 492 KB Output is correct
8 Correct 29 ms 492 KB Output is correct
9 Correct 29 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 364 KB Output is correct
2 Correct 10 ms 492 KB Output is correct
3 Correct 14 ms 492 KB Output is correct
4 Correct 23 ms 620 KB Output is correct
5 Correct 28 ms 492 KB Output is correct
6 Correct 29 ms 524 KB Output is correct
7 Correct 28 ms 492 KB Output is correct
8 Correct 29 ms 492 KB Output is correct
9 Correct 29 ms 492 KB Output is correct
10 Correct 76 ms 748 KB Output is correct
11 Correct 17 ms 492 KB Output is correct
12 Correct 984 ms 6052 KB Output is correct
13 Correct 190 ms 3308 KB Output is correct
14 Correct 2413 ms 10988 KB Output is correct
15 Correct 2516 ms 11260 KB Output is correct
16 Correct 2733 ms 12136 KB Output is correct
17 Correct 2916 ms 12652 KB Output is correct
18 Correct 2860 ms 12304 KB Output is correct
19 Correct 3016 ms 13000 KB Output is correct
20 Correct 2989 ms 13144 KB Output is correct
21 Correct 2904 ms 13008 KB Output is correct