Submission #534301

# Submission time Handle Problem Language Result Execution time Memory
534301 2022-03-08T03:38:56 Z pavement Furniture (JOI20_furniture) C++17
100 / 100
327 ms 35544 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
#define int long long
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define g0(a) get<0>(a)
#define g1(a) get<1>(a)
#define g2(a) get<2>(a)
#define g3(a) get<3>(a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
using db = double;
using ll = long long;
using ld = long double;
using ii = pair<int, int>;
using iii = tuple<int, int, int>;
using iiii = tuple<int, int, int, int>;
template<class key, class value = null_type, class cmp = less<key> >
using ordered_set = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

int N, M, Q, R[1005][1005], cnt[2005], T[2][1005][1005], dr[] = {-1, 0, 0, 1}, dc[] = {0, -1, 1, 0};
bool C;

void rem(int r, int c) {
	if (R[r][c]) return;
	R[r][c] = 1;
	cnt[r + c]--;
	for (int k = 0; k < 4; k++) {
		if (1 <= r + dr[k] && r + dr[k] <= N && 1 <= c + dc[k] && c + dc[k] <= M) {
			T[k / 2][r + dr[k]][c + dc[k]]--;
			if (T[k / 2][r + dr[k]][c + dc[k]] == 0) rem(r + dr[k], c + dc[k]);
		}
	}
}

main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> N >> M;
	for (int i = 1; i <= N; i++)
		for (int j = 1; j <= M; j++) {
			cnt[i + j]++;
			T[0][i][j] = 2 - (i == N) - (j == M);
			T[1][i][j] = 2 - (i == 1) - (j == 1);
		}
	for (int i = 1; i <= N; i++)
		for (int j = 1; j <= M; j++) {
			cin >> C;
			if (C == 1) rem(i, j);
		}
	cin >> Q;
	for (int r, c; Q--; ) {
		cin >> r >> c;
		if (R[r][c]) cout << "1\n";
		else if (cnt[r + c] == 1) cout << "0\n";
		else {
			cout << "1\n";
			rem(r, c);
		}
	}
}

Compilation message

furniture.cpp:44:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   44 | main() {
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1228 KB Output is correct
2 Correct 2 ms 1616 KB Output is correct
3 Correct 2 ms 1620 KB Output is correct
4 Correct 4 ms 1740 KB Output is correct
5 Correct 3 ms 1740 KB Output is correct
6 Correct 3 ms 1868 KB Output is correct
7 Correct 4 ms 1776 KB Output is correct
8 Correct 3 ms 1868 KB Output is correct
9 Correct 4 ms 1868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1228 KB Output is correct
2 Correct 2 ms 1616 KB Output is correct
3 Correct 2 ms 1620 KB Output is correct
4 Correct 4 ms 1740 KB Output is correct
5 Correct 3 ms 1740 KB Output is correct
6 Correct 3 ms 1868 KB Output is correct
7 Correct 4 ms 1776 KB Output is correct
8 Correct 3 ms 1868 KB Output is correct
9 Correct 4 ms 1868 KB Output is correct
10 Correct 10 ms 2124 KB Output is correct
11 Correct 3 ms 1228 KB Output is correct
12 Correct 210 ms 28408 KB Output is correct
13 Correct 82 ms 24756 KB Output is correct
14 Correct 316 ms 31896 KB Output is correct
15 Correct 282 ms 32088 KB Output is correct
16 Correct 270 ms 33388 KB Output is correct
17 Correct 321 ms 35136 KB Output is correct
18 Correct 327 ms 34136 KB Output is correct
19 Correct 325 ms 35504 KB Output is correct
20 Correct 254 ms 35544 KB Output is correct
21 Correct 292 ms 35520 KB Output is correct