結果
問題 | No.2696 Sign Creation |
ユーザー | rlangevin |
提出日時 | 2024-03-28 12:20:03 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 503 ms / 2,500 ms |
コード長 | 2,732 bytes |
コンパイル時間 | 196 ms |
コンパイル使用メモリ | 82,260 KB |
実行使用メモリ | 82,720 KB |
最終ジャッジ日時 | 2024-05-17 18:25:43 |
合計ジャッジ時間 | 7,035 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 48 ms
60,252 KB |
testcase_01 | AC | 49 ms
60,732 KB |
testcase_02 | AC | 43 ms
54,132 KB |
testcase_03 | AC | 49 ms
59,684 KB |
testcase_04 | AC | 44 ms
53,800 KB |
testcase_05 | AC | 48 ms
60,272 KB |
testcase_06 | AC | 45 ms
53,276 KB |
testcase_07 | AC | 44 ms
54,544 KB |
testcase_08 | AC | 103 ms
76,608 KB |
testcase_09 | AC | 63 ms
65,292 KB |
testcase_10 | AC | 115 ms
76,764 KB |
testcase_11 | AC | 68 ms
68,328 KB |
testcase_12 | AC | 70 ms
68,260 KB |
testcase_13 | AC | 359 ms
79,764 KB |
testcase_14 | AC | 335 ms
80,624 KB |
testcase_15 | AC | 305 ms
80,120 KB |
testcase_16 | AC | 325 ms
79,824 KB |
testcase_17 | AC | 129 ms
77,120 KB |
testcase_18 | AC | 158 ms
77,756 KB |
testcase_19 | AC | 293 ms
79,720 KB |
testcase_20 | AC | 75 ms
70,640 KB |
testcase_21 | AC | 285 ms
80,592 KB |
testcase_22 | AC | 182 ms
78,048 KB |
testcase_23 | AC | 277 ms
80,056 KB |
testcase_24 | AC | 281 ms
80,192 KB |
testcase_25 | AC | 244 ms
78,952 KB |
testcase_26 | AC | 155 ms
77,556 KB |
testcase_27 | AC | 177 ms
77,504 KB |
testcase_28 | AC | 152 ms
77,200 KB |
testcase_29 | AC | 120 ms
77,440 KB |
testcase_30 | AC | 170 ms
77,116 KB |
testcase_31 | AC | 503 ms
82,720 KB |
testcase_32 | AC | 42 ms
59,172 KB |
testcase_33 | AC | 51 ms
63,100 KB |
testcase_34 | AC | 46 ms
61,096 KB |
testcase_35 | AC | 39 ms
53,616 KB |
testcase_36 | AC | 38 ms
53,980 KB |
testcase_37 | AC | 39 ms
53,208 KB |
testcase_38 | AC | 39 ms
53,624 KB |
testcase_39 | AC | 38 ms
52,812 KB |
testcase_40 | AC | 37 ms
53,120 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) SS = [[-1] * (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 SS[X[i]][Y[i]] = i 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 SS[a][b] == -1: continue U.union(i, SS[a][b]) mi, ma = 10 ** 18, -10 ** 18 for i in range(H): for j in range(W): if SS[i][j] != -1: continue S = set() v1, v2 = 0, 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 SS[a][b] == -1: continue ind = U.find(SS[a][b]) if ind in S: continue S.add(ind) if U.get_size(ind) >= 2: v2 += 1 else: v1 += 1 if v1 == 0: if v2 == 0: mi = min(mi, 0) ma = max(ma, 0) else: mi = min(mi, v2 - 1) ma = max(ma, v2 - 1) else: if v2 == 0: mi = min(mi, -1) ma = max(ma, -1) else: mi = min(mi, v2 - 1) ma = max(ma, v2 - 1) 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 - ma, ans - mi)