結果

問題 No.2696 Sign Creation
ユーザー Carpenters-CatCarpenters-Cat
提出日時 2024-03-22 23:25:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 81 ms / 2,500 ms
コード長 1,599 bytes
コンパイル時間 1,982 ms
コンパイル使用メモリ 213,532 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-17 18:20:32
合計ジャッジ時間 3,532 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 3 ms
6,944 KB
testcase_09 AC 3 ms
6,940 KB
testcase_10 AC 3 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 3 ms
6,940 KB
testcase_13 AC 71 ms
6,940 KB
testcase_14 AC 31 ms
6,944 KB
testcase_15 AC 27 ms
6,940 KB
testcase_16 AC 64 ms
6,944 KB
testcase_17 AC 10 ms
6,940 KB
testcase_18 AC 11 ms
6,944 KB
testcase_19 AC 32 ms
6,940 KB
testcase_20 AC 2 ms
6,944 KB
testcase_21 AC 26 ms
6,940 KB
testcase_22 AC 17 ms
6,940 KB
testcase_23 AC 28 ms
6,940 KB
testcase_24 AC 28 ms
6,940 KB
testcase_25 AC 38 ms
6,944 KB
testcase_26 AC 11 ms
6,940 KB
testcase_27 AC 14 ms
6,940 KB
testcase_28 AC 10 ms
6,944 KB
testcase_29 AC 12 ms
6,944 KB
testcase_30 AC 11 ms
6,940 KB
testcase_31 AC 81 ms
6,940 KB
testcase_32 AC 1 ms
6,944 KB
testcase_33 AC 2 ms
6,944 KB
testcase_34 AC 2 ms
6,940 KB
testcase_35 AC 1 ms
6,940 KB
testcase_36 AC 2 ms
6,944 KB
testcase_37 AC 2 ms
6,940 KB
testcase_38 AC 1 ms
6,940 KB
testcase_39 AC 2 ms
6,940 KB
testcase_40 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
int par[200020];
int siz[200020];
void init(int N) {
	iota(par, par + N, 0);
	fill(siz, siz + N, 1);
}
int root(int v) {
	return par[v] = (par[v] == v ? v : root(par[v]));
}
void merge(int a, int b) {
	a = root(a); b = root(b);
	if (a == b) return;
	if (siz[a] < siz[b]) swap(a, b);
	par[b] = a;
	siz[a] += b;
}
int main () {
	int H, W, N, D;
	cin >> H >> W >> N >> D;
	vector ST(H + 20, vector(W + 20, -1));
	init(N);
	for (int i = 0; i < N; i ++) {
		int a, b;
		cin >> a >> b;
		ST[a + 9][b + 9] = i;
	}
	for (int h = 10; h <= H + 10; h ++) {
		for (int w = 10; w <= W + 10; w ++) {
			if (ST[h][w] == -1) continue;
			int p = ST[h][w];
			for (int di = -D; di <= D; di ++) {
				int abb = D - abs(di);
				for (int dj = -abb; dj <= abb; dj ++) {
					int q = ST[h + di][w + dj];
					if (q != -1) {
						merge(p, q);
					}
				}
			}
		}
	}
	int ma = -1, mi = N + 100;
	int now = 0;
	for (int i = 0; i < N; i ++) {
		if (root(i) == i && siz[i] > 1) {
			now ++;
		}
	}
	for (int i = 10; i < H + 10; i ++) {
		for (int j = 10; j < W + 10; j ++) {
			if (ST[i][j] != -1) continue;
			unordered_set<int> st;
			int pq = 0;
			for (int di = -D; di <= D; di ++) {
				int abb = D - abs(di);
				for (int dj = -abb; dj <= abb; dj ++) {
					int iid = ST[i + di][j + dj];
					if (iid != -1) {
						pq ++;
						if (siz[root(iid)] > 1) {
							st.insert(root(ST[i + di][j + dj]));
						}
					}
				}
			}
			int sz = st.size();
			int nns = (pq ? now - sz + 1 : now);
			mi = min(mi, nns); ma = max(ma, nns);
		}
	}
	cout << mi << " " << ma << endl;
}
0