結果
問題 | No.2696 Sign Creation |
ユーザー | PNJ |
提出日時 | 2024-03-22 22:48:17 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 667 ms / 2,500 ms |
コード長 | 2,340 bytes |
コンパイル時間 | 232 ms |
コンパイル使用メモリ | 82,532 KB |
実行使用メモリ | 104,584 KB |
最終ジャッジ日時 | 2024-05-17 18:16:20 |
合計ジャッジ時間 | 11,741 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 85 ms
84,648 KB |
testcase_01 | AC | 81 ms
84,384 KB |
testcase_02 | AC | 56 ms
70,504 KB |
testcase_03 | AC | 62 ms
72,264 KB |
testcase_04 | AC | 90 ms
84,536 KB |
testcase_05 | AC | 64 ms
73,864 KB |
testcase_06 | AC | 63 ms
73,844 KB |
testcase_07 | AC | 62 ms
73,296 KB |
testcase_08 | AC | 186 ms
86,984 KB |
testcase_09 | AC | 102 ms
85,584 KB |
testcase_10 | AC | 200 ms
87,360 KB |
testcase_11 | AC | 122 ms
86,324 KB |
testcase_12 | AC | 122 ms
86,596 KB |
testcase_13 | AC | 615 ms
95,584 KB |
testcase_14 | AC | 542 ms
96,080 KB |
testcase_15 | AC | 491 ms
95,148 KB |
testcase_16 | AC | 514 ms
102,568 KB |
testcase_17 | AC | 260 ms
90,572 KB |
testcase_18 | AC | 487 ms
93,368 KB |
testcase_19 | AC | 516 ms
104,584 KB |
testcase_20 | AC | 140 ms
87,040 KB |
testcase_21 | AC | 424 ms
95,560 KB |
testcase_22 | AC | 400 ms
97,264 KB |
testcase_23 | AC | 496 ms
95,636 KB |
testcase_24 | AC | 514 ms
95,420 KB |
testcase_25 | AC | 629 ms
95,196 KB |
testcase_26 | AC | 320 ms
104,384 KB |
testcase_27 | AC | 328 ms
92,804 KB |
testcase_28 | AC | 320 ms
92,816 KB |
testcase_29 | AC | 317 ms
99,048 KB |
testcase_30 | AC | 332 ms
96,276 KB |
testcase_31 | AC | 667 ms
100,952 KB |
testcase_32 | AC | 83 ms
84,420 KB |
testcase_33 | AC | 102 ms
85,356 KB |
testcase_34 | AC | 101 ms
86,064 KB |
testcase_35 | AC | 57 ms
69,320 KB |
testcase_36 | AC | 56 ms
69,752 KB |
testcase_37 | AC | 56 ms
69,716 KB |
testcase_38 | AC | 53 ms
70,024 KB |
testcase_39 | AC | 58 ms
72,164 KB |
testcase_40 | AC | 58 ms
71,928 KB |
ソースコード
from collections import defaultdict class UnionFind(): def __init__(self, n): self.n = n self.root = [-1]*(n+1) self.rank = [0]*(n+1) def find(self, x): if(self.root[x] < 0): return x else: self.root[x] = self.find(self.root[x]) return self.root[x] def unite(self, x, y): x = self.find(x) y = self.find(y) if(x == y): return elif(self.rank[x] > self.rank[y]): self.root[x] += self.root[y] self.root[y] = x else: self.root[y] += self.root[x] self.root[x] = y if(self.rank[x] == self.rank[y]): self.rank[y] += 1 def same(self, x, y): return self.find(x) == self.find(y) def size(self, x): return -self.root[self.find(x)] def roots(self): return [i for i, x in enumerate(self.root) if x < 0] def group_size(self): return len(self.roots()) def group_members(self): group_members = defaultdict(list) for member in range(self.n): group_members[self.find(member)].append(member) return group_members H,W,N,D = map(int,input().split()) star = [[0 for j in range(W+1000)] for i in range(H+1000)] SS = [] for i in range(N): x,y = map(int,input().split()) star[x][y] = i+1 SS.append((x,y)) uf = UnionFind(N) for i in range(N): u = i + 1 x,y = SS[i] for dh in range(-5,6): for dw in range(-5,6): if abs(dh) + abs(dw) > D: continue v = star[x+dh][y+dw] if v == 0: continue uf.unite(u,v) R = [0 for i in range(N+1)] for u in range(1,N+1): r = uf.find(u) R[r] += 1 size = 0 for i in range(N+1): if R[i] > 1: size += 1 M = 0 m = N for h in range(1,H+1): for w in range(1,W+1): if star[h][w]: continue S = set() for dh in range(-5,6): for dw in range(-5,6): if abs(dh) + abs(dw) > D: continue if star[h+dh][w+dw] > 0: v = star[h+dh][w+dw] r = uf.find(v) S.add(r) S = list(S) s = 0 f = 0 for r in S: if R[r] == 1: f = 1 continue s += 1 if s > 0: s = s - 1 else: s = -f m = min(size - s,m) M = max(size - s,M) print(m,M)