結果
問題 | No.2696 Sign Creation |
ユーザー | mkawa2 |
提出日時 | 2024-03-23 01:58:05 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,019 ms / 2,500 ms |
コード長 | 2,795 bytes |
コンパイル時間 | 137 ms |
コンパイル使用メモリ | 82,980 KB |
実行使用メモリ | 105,200 KB |
最終ジャッジ日時 | 2024-05-17 18:22:25 |
合計ジャッジ時間 | 8,998 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 46 ms
63,096 KB |
testcase_01 | AC | 46 ms
61,860 KB |
testcase_02 | AC | 43 ms
55,832 KB |
testcase_03 | AC | 41 ms
55,888 KB |
testcase_04 | AC | 43 ms
57,004 KB |
testcase_05 | AC | 42 ms
55,472 KB |
testcase_06 | AC | 41 ms
55,868 KB |
testcase_07 | AC | 42 ms
56,108 KB |
testcase_08 | AC | 133 ms
77,972 KB |
testcase_09 | AC | 72 ms
74,056 KB |
testcase_10 | AC | 157 ms
78,588 KB |
testcase_11 | AC | 84 ms
76,548 KB |
testcase_12 | AC | 84 ms
76,204 KB |
testcase_13 | AC | 644 ms
87,040 KB |
testcase_14 | AC | 368 ms
86,104 KB |
testcase_15 | AC | 366 ms
86,792 KB |
testcase_16 | AC | 619 ms
86,304 KB |
testcase_17 | AC | 156 ms
77,664 KB |
testcase_18 | AC | 207 ms
79,724 KB |
testcase_19 | AC | 378 ms
83,432 KB |
testcase_20 | AC | 101 ms
76,792 KB |
testcase_21 | AC | 308 ms
87,428 KB |
testcase_22 | AC | 236 ms
79,492 KB |
testcase_23 | AC | 330 ms
83,476 KB |
testcase_24 | AC | 333 ms
83,752 KB |
testcase_25 | AC | 453 ms
82,740 KB |
testcase_26 | AC | 182 ms
78,020 KB |
testcase_27 | AC | 183 ms
78,944 KB |
testcase_28 | AC | 194 ms
78,772 KB |
testcase_29 | AC | 137 ms
77,600 KB |
testcase_30 | AC | 199 ms
78,224 KB |
testcase_31 | AC | 1,019 ms
105,200 KB |
testcase_32 | AC | 46 ms
60,988 KB |
testcase_33 | AC | 64 ms
71,060 KB |
testcase_34 | AC | 45 ms
56,648 KB |
testcase_35 | AC | 41 ms
54,628 KB |
testcase_36 | AC | 42 ms
56,208 KB |
testcase_37 | AC | 42 ms
54,432 KB |
testcase_38 | AC | 42 ms
55,452 KB |
testcase_39 | AC | 42 ms
55,112 KB |
testcase_40 | AC | 43 ms
55,976 KB |
ソースコード
import sys # sys.setrecursionlimit(200005) # sys.set_int_max_str_digits(200005) int1 = lambda x: int(x)-1 pDB = lambda *x: print(*x, end="\n", file=sys.stderr) p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr) def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() # dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] inf = -1-(-1 << 31) # inf = -1-(-1 << 62) # md = 10**9+7 md = 998244353 class UnionFind: def __init__(self, n): self.table = [-1]*n self.mem = [[u] for u in range(n)] self.cnt = n def root(self, u): stack = [] while self.table[u] >= 0: stack.append(u) u = self.table[u] for v in stack: self.table[v] = u return u def same(self, u, v): return self.root(u) == self.root(v) def merge(self, u, v): u = self.root(u) v = self.root(v) if u == v: return False su = -self.table[u] sv = -self.table[v] if su < sv: u, v = v, u self.table[u] = -su-sv self.table[v] = u self.mem[u] += self.mem[v] self.mem[v].clear() self.cnt -= 1 return True def member(self, u): return self.mem[self.root(u)] # グループの要素数 def size(self, u): return -self.table[self.root(u)] from collections import Counter h, w, n, d = LI() t = [-1]*h*w ij = [] uf = UnionFind(n) for u in range(n): i, j = LI1() t[i*w+j] = u ij.append((i, j)) for x in range(max(0, i-d), min(h, i+d+1)): e = d-abs(i-x) for y in range(max(0, j-e), min(w, j+e+1)): p = x*w+y if t[p] != -1: uf.merge(u, t[p]) s = set() for u in range(n): u = uf.root(u) if uf.size(u) > 1: s.add(u) s = len(s) mn = mx = s for i in range(h): for j in range(w): if t[i*w+j] == -1: st = set() one = 0 for x in range(max(0, i-d), min(h, i+d+1)): e = d-abs(i-x) for y in range(max(0, j-e), min(w, j+e+1)): p = x*w+y if t[p] != -1: v = t[p] if uf.size(v) == 1: one = 1 else: st.add(uf.root(v)) if st: mn = min(mn, s-len(st)+1) elif one: mx = max(mx, s+1) print(mn, mx)