Submission #377160

# Submission time Handle Problem Language Result Execution time Memory
377160 2021-03-13T05:33:06 Z reymontada61 Furniture (JOI20_furniture) C++14
100 / 100
3040 ms 16096 KB
#include <bits/stdc++.h>
using namespace std;

int n, m;
const int MXN = 1005;

int grid[MXN][MXN];

void place(int a, int b) {
	if (grid[a][b] == 0) return;
	grid[a][b] = 0;
	{
		if (grid[a-1][b+1] == 0) {
			place(a, b+1);
			place(a-1, b);
		}
	}
	{
		if (grid[a+1][b-1] == 0) {
			place(a+1, b);
			place(a, b-1);
		}
	}
}

int oper(int x, int y) {
	
	if (grid[x][y] == 0) {
		place(x, y);
		return 1;
	}
	
	int tr = 0;

	for (int on=1; on<=n; on++) {
		int ot = x + y - on;
		if (1 <= ot && ot <= m) {
			if (grid[on][ot]) tr++;
		}
	}
	
	if (tr > 1) {
		place(x, y);
		return 1;
	}
	else {
		return 0;
	}
	
}

signed main() {

	cin >> n >> m;

	for (int i=1; i<=n; i++) {
		for (int j=1; j<=m; j++) {
			grid[i][j] = 1; 
		}
	}
	
	int x;
	for (int i=1; i<=n; i++) {
		for (int j=1; j<=m; j++) {
			cin >> x;
			if (x == 1) {
				oper(i, j);
			}
		}
	}
	
	int q;
	cin >> q;
	while (q--) {
		int x, y;
		cin >> x >> y;
		cout << oper(x, y) << endl;
	}

}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 620 KB Output is correct
2 Correct 11 ms 876 KB Output is correct
3 Correct 13 ms 748 KB Output is correct
4 Correct 26 ms 876 KB Output is correct
5 Correct 25 ms 1004 KB Output is correct
6 Correct 29 ms 876 KB Output is correct
7 Correct 35 ms 876 KB Output is correct
8 Correct 34 ms 896 KB Output is correct
9 Correct 29 ms 876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 620 KB Output is correct
2 Correct 11 ms 876 KB Output is correct
3 Correct 13 ms 748 KB Output is correct
4 Correct 26 ms 876 KB Output is correct
5 Correct 25 ms 1004 KB Output is correct
6 Correct 29 ms 876 KB Output is correct
7 Correct 35 ms 876 KB Output is correct
8 Correct 34 ms 896 KB Output is correct
9 Correct 29 ms 876 KB Output is correct
10 Correct 74 ms 1004 KB Output is correct
11 Correct 19 ms 748 KB Output is correct
12 Correct 1316 ms 9252 KB Output is correct
13 Correct 333 ms 5996 KB Output is correct
14 Correct 2858 ms 13928 KB Output is correct
15 Correct 2902 ms 14000 KB Output is correct
16 Correct 2726 ms 15084 KB Output is correct
17 Correct 2895 ms 15976 KB Output is correct
18 Correct 3022 ms 15272 KB Output is correct
19 Correct 2955 ms 16096 KB Output is correct
20 Correct 3035 ms 15852 KB Output is correct
21 Correct 3040 ms 15956 KB Output is correct