답안 #685729

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
685729 2023-01-24T22:38:10 Z NK_ Furniture (JOI20_furniture) C++17
100 / 100
302 ms 19956 KB
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>

using namespace std;

#define nl '\n'

int main() {
	cin.tie(0)->sync_with_stdio(0);
	
	int N, M; cin >> N >> M;
	vector<vector<int>> A(N+2, vector<int>(M+2));
	vector<vector<int>> R(N+2, vector<int>(M+2, 1));

	for(int i = 1; i <= N; i++) for(int j = 1; j <= M; j++) R[i][j] = 0;

	vector<int> C(N+M+1, 0);

	function<void(int, int)> fix = [&](int r, int c) {

		R[r][c] = 1;
		C[r+c]--;
		if (R[r+1][c-1] && !R[r+1][c]) fix(r+1, c);
		if (R[r+1][c-1] && !R[r][c-1]) fix(r, c-1);
		if (R[r-1][c+1] && !R[r-1][c]) fix(r-1, c);
		if (R[r-1][c+1] && !R[r][c+1]) fix(r, c+1);
	};

	for(int i = 1; i <= N; i++) for(int j = 1; j <= M; j++) {
		cin >> A[i][j];
		C[i+j]++;

		if (A[i][j] && !R[i][j]) fix(i, j);
	}

	int Q; cin >> Q;
	for(int q = 0; q < Q; q++) {
		int r, c; cin >> r >> c;
		if (R[r][c]) cout << 1 << nl;
		else if (C[r+c] == 1) cout << 0 << nl;
		else {
			cout << 1 << nl;
			fix(r, c);
		}
	}



    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 3 ms 468 KB Output is correct
5 Correct 3 ms 456 KB Output is correct
6 Correct 3 ms 472 KB Output is correct
7 Correct 4 ms 468 KB Output is correct
8 Correct 5 ms 492 KB Output is correct
9 Correct 4 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 3 ms 468 KB Output is correct
5 Correct 3 ms 456 KB Output is correct
6 Correct 3 ms 472 KB Output is correct
7 Correct 4 ms 468 KB Output is correct
8 Correct 5 ms 492 KB Output is correct
9 Correct 4 ms 468 KB Output is correct
10 Correct 8 ms 1108 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 139 ms 12520 KB Output is correct
13 Correct 51 ms 9164 KB Output is correct
14 Correct 230 ms 16988 KB Output is correct
15 Correct 227 ms 16852 KB Output is correct
16 Correct 232 ms 18296 KB Output is correct
17 Correct 280 ms 19224 KB Output is correct
18 Correct 236 ms 18892 KB Output is correct
19 Correct 248 ms 19868 KB Output is correct
20 Correct 242 ms 19956 KB Output is correct
21 Correct 302 ms 19864 KB Output is correct