結果
問題 | No.2696 Sign Creation |
ユーザー | rlangevin |
提出日時 | 2024-03-22 22:27:06 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,461 bytes |
コンパイル時間 | 164 ms |
コンパイル使用メモリ | 82,564 KB |
実行使用メモリ | 97,944 KB |
最終ジャッジ日時 | 2024-05-17 18:13:34 |
合計ジャッジ時間 | 8,018 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
62,092 KB |
testcase_01 | AC | 40 ms
60,780 KB |
testcase_02 | AC | 35 ms
53,024 KB |
testcase_03 | AC | 41 ms
59,944 KB |
testcase_04 | AC | 39 ms
54,472 KB |
testcase_05 | AC | 41 ms
59,268 KB |
testcase_06 | AC | 37 ms
53,612 KB |
testcase_07 | AC | 39 ms
53,480 KB |
testcase_08 | AC | 99 ms
77,284 KB |
testcase_09 | AC | 51 ms
64,600 KB |
testcase_10 | AC | 98 ms
77,480 KB |
testcase_11 | AC | 55 ms
66,880 KB |
testcase_12 | AC | 57 ms
66,240 KB |
testcase_13 | AC | 500 ms
83,092 KB |
testcase_14 | AC | 341 ms
83,612 KB |
testcase_15 | AC | 313 ms
83,116 KB |
testcase_16 | AC | 493 ms
83,120 KB |
testcase_17 | AC | 102 ms
74,724 KB |
testcase_18 | AC | 139 ms
78,364 KB |
testcase_19 | AC | 289 ms
82,416 KB |
testcase_20 | AC | 62 ms
68,832 KB |
testcase_21 | AC | 320 ms
86,024 KB |
testcase_22 | AC | 209 ms
78,468 KB |
testcase_23 | AC | 293 ms
82,784 KB |
testcase_24 | AC | 308 ms
82,652 KB |
testcase_25 | AC | 289 ms
81,376 KB |
testcase_26 | AC | 140 ms
77,568 KB |
testcase_27 | AC | 172 ms
78,152 KB |
testcase_28 | AC | 158 ms
77,976 KB |
testcase_29 | AC | 143 ms
76,812 KB |
testcase_30 | AC | 134 ms
77,560 KB |
testcase_31 | AC | 1,428 ms
97,944 KB |
testcase_32 | AC | 41 ms
59,984 KB |
testcase_33 | AC | 49 ms
65,552 KB |
testcase_34 | AC | 43 ms
61,832 KB |
testcase_35 | AC | 34 ms
53,668 KB |
testcase_36 | AC | 36 ms
54,640 KB |
testcase_37 | AC | 34 ms
53,760 KB |
testcase_38 | AC | 34 ms
53,268 KB |
testcase_39 | WA | - |
testcase_40 | AC | 35 ms
53,884 KB |
ソースコード
import sys input = sys.stdin.readline class UnionFind(): def __init__(self, n=1): self.par = [i for i in range(n)] self.rank = [0 for _ in range(n)] self.size = [1 for _ in range(n)] def find(self, x): if self.par[x] == x: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x != y: if self.rank[x] < self.rank[y]: x, y = y, x if self.rank[x] == self.rank[y]: self.rank[x] += 1 self.par[y] = x self.size[x] += self.size[y] def is_same(self, x, y): return self.find(x) == self.find(y) def get_size(self, x): x = self.find(x) return self.size[x] H, W, N, D = map(int, input().split()) X, Y = [0] * N, [0] * N U = UnionFind(N) DD = dict() SS = [[0] * (W + 1) for _ in range(H + 1)] for i in range(N): X[i], Y[i] = map(int, input().split()) X[i], Y[i] = X[i] - 1, Y[i] - 1 DD[(X[i], Y[i])] = i SS[X[i]][Y[i]] = 1 L = [] for a in range(-D, D + 1): for b in range(-D, D + 1): if abs(a) + abs(b) > D: continue L.append((a, b)) for i in range(N): for dx, dy in L: a = X[i] + dx b = Y[i] + dy if a < 0 or a > H - 1 or b < 0 or b > W - 1: continue if not SS[a][b]: continue ind = DD[(a, b)] U.union(i, ind) mi, ma = 0, -10 ** 18 for i in range(H): for j in range(W): if SS[i][j]: continue S = set() v = 0 flag = 0 for dx, dy in L: a = i + dx b = j + dy if a < 0 or a > H - 1 or b < 0 or b > W - 1: continue if not SS[a][b]: continue ind = U.find(DD[(a, b)]) if ind in S: continue S.add(ind) if U.get_size(ind) >= 2: v -= 1 else: flag = 1 if v < 0: v += 1 mi = min(mi, v + flag) ma = max(ma, v + flag) ans = 0 S = set() for i in range(N): if U.find(i) in S: continue S.add(U.find(i)) if U.get_size(i) >= 2: ans += 1 print(ans + mi, ans + ma)