結果
問題 | No.2696 Sign Creation |
ユーザー | detteiuu |
提出日時 | 2024-08-10 16:10:48 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,303 ms / 2,500 ms |
コード長 | 2,511 bytes |
コンパイル時間 | 356 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 114,396 KB |
最終ジャッジ日時 | 2024-08-10 16:11:03 |
合計ジャッジ時間 | 12,530 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 40 ms
53,504 KB |
testcase_01 | AC | 36 ms
53,376 KB |
testcase_02 | AC | 35 ms
53,120 KB |
testcase_03 | AC | 36 ms
53,248 KB |
testcase_04 | AC | 39 ms
54,144 KB |
testcase_05 | AC | 35 ms
53,504 KB |
testcase_06 | AC | 34 ms
53,632 KB |
testcase_07 | AC | 35 ms
53,376 KB |
testcase_08 | AC | 132 ms
78,312 KB |
testcase_09 | AC | 61 ms
70,784 KB |
testcase_10 | AC | 169 ms
78,888 KB |
testcase_11 | AC | 71 ms
76,288 KB |
testcase_12 | AC | 70 ms
76,152 KB |
testcase_13 | AC | 986 ms
87,188 KB |
testcase_14 | AC | 663 ms
87,628 KB |
testcase_15 | AC | 564 ms
87,404 KB |
testcase_16 | AC | 886 ms
87,200 KB |
testcase_17 | AC | 135 ms
77,056 KB |
testcase_18 | AC | 458 ms
80,404 KB |
testcase_19 | AC | 740 ms
85,532 KB |
testcase_20 | AC | 109 ms
77,240 KB |
testcase_21 | AC | 573 ms
92,672 KB |
testcase_22 | AC | 549 ms
80,192 KB |
testcase_23 | AC | 599 ms
86,132 KB |
testcase_24 | AC | 597 ms
86,236 KB |
testcase_25 | AC | 751 ms
83,088 KB |
testcase_26 | AC | 185 ms
77,544 KB |
testcase_27 | AC | 276 ms
79,196 KB |
testcase_28 | AC | 317 ms
79,812 KB |
testcase_29 | AC | 257 ms
78,736 KB |
testcase_30 | AC | 273 ms
78,496 KB |
testcase_31 | AC | 1,303 ms
114,396 KB |
testcase_32 | AC | 36 ms
53,120 KB |
testcase_33 | AC | 43 ms
64,896 KB |
testcase_34 | AC | 42 ms
61,824 KB |
testcase_35 | AC | 34 ms
53,248 KB |
testcase_36 | AC | 35 ms
52,992 KB |
testcase_37 | AC | 34 ms
52,864 KB |
testcase_38 | AC | 34 ms
52,864 KB |
testcase_39 | AC | 33 ms
53,120 KB |
testcase_40 | AC | 34 ms
53,120 KB |
ソースコード
from bisect import bisect_left, bisect_right class UnionFind: def __init__(self,n): self.n = n self.parent_size = [-1]*n def leader(self,a): if self.parent_size[a] < 0: return a self.parent_size[a] = self.leader(self.parent_size[a]) return self.parent_size[a] def merge(self,a,b): x, y = self.leader(a), self.leader(b) if x == y: return if abs(self.parent_size[x]) < abs(self.parent_size[y]): x, y = y, x self.parent_size[x] += self.parent_size[y] self.parent_size[y] = x return def same(self,a,b): return self.leader(a) == self.leader(b) def size(self,a): return abs(self.parent_size[self.leader(a)]) def groups(self): result = [[] for _ in range(self.n)] for i in range(self.n): result[self.leader(i)].append(i) return [r for r in result if r != []] H, W, N, D = map(int, input().split()) XY = [list(map(int, input().split())) for _ in range(N)] idx = dict() xyD = dict() for i in range(N): X, Y = XY[i] idx[(X, Y)] = i if X in xyD: xyD[X].append(Y) else: xyD[X] = [Y] for i in xyD.keys(): xyD[i].sort() UF = UnionFind(N) for i in range(N): X, Y = XY[i] for dx in range(D+1): for dy in range(-D, D+1): if abs(dx)+abs(dy) > D: continue nx, ny = X+dx, Y+dy if (nx, ny) in idx: UF.merge(i, idx[(nx, ny)]) def func(x, y): S = set() for dx in range(-D, D+1): nx = x+dx if nx not in xyD: continue left = y-(D-abs(dx)) right = y+(D-abs(dx)) lb = bisect_left(xyD[nx], left) rb = bisect_right(xyD[nx], right) for i in range(lb, rb): S.add(UF.leader(idx[(nx, xyD[nx][i])])) if len(S) == 0: return L else: cnt = dict() for s in S: if UF.size(s) in cnt: cnt[UF.size(s)] += 1 else: cnt[UF.size(s)] = 1 if 1 in cnt: cnt.pop(1) c = sum(i for i in cnt.values()) return L+1-c INF = 10**18 ansMIN = INF ansMAX = -INF L = sum(len(g) >= 2 for g in UF.groups()) for x in range(1, H+1): for y in range(1, W+1): if (x, y) in idx: continue cnt = func(x, y) ansMIN = min(ansMIN, cnt) ansMAX = max(ansMAX, cnt) print(ansMIN, ansMAX)