結果
問題 | No.2696 Sign Creation |
ユーザー | mo124121 |
提出日時 | 2024-02-04 10:06:15 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,854 bytes |
コンパイル時間 | 396 ms |
コンパイル使用メモリ | 82,148 KB |
実行使用メモリ | 122,560 KB |
最終ジャッジ日時 | 2024-12-20 11:53:24 |
合計ジャッジ時間 | 20,553 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 46 ms
63,684 KB |
testcase_01 | AC | 46 ms
54,980 KB |
testcase_02 | AC | 52 ms
62,480 KB |
testcase_03 | AC | 59 ms
65,752 KB |
testcase_04 | AC | 63 ms
65,428 KB |
testcase_05 | AC | 61 ms
67,232 KB |
testcase_06 | AC | 47 ms
55,308 KB |
testcase_07 | AC | 49 ms
54,644 KB |
testcase_08 | AC | 236 ms
78,328 KB |
testcase_09 | AC | 49 ms
55,924 KB |
testcase_10 | AC | 176 ms
78,440 KB |
testcase_11 | AC | 46 ms
55,868 KB |
testcase_12 | AC | 47 ms
55,016 KB |
testcase_13 | TLE | - |
testcase_14 | AC | 943 ms
99,812 KB |
testcase_15 | AC | 950 ms
97,708 KB |
testcase_16 | TLE | - |
testcase_17 | AC | 47 ms
56,784 KB |
testcase_18 | AC | 283 ms
83,820 KB |
testcase_19 | AC | 1,046 ms
98,980 KB |
testcase_20 | AC | 58 ms
65,836 KB |
testcase_21 | AC | 644 ms
98,756 KB |
testcase_22 | AC | 351 ms
83,184 KB |
testcase_23 | AC | 807 ms
97,820 KB |
testcase_24 | AC | 812 ms
97,440 KB |
testcase_25 | AC | 1,346 ms
100,416 KB |
testcase_26 | AC | 132 ms
78,324 KB |
testcase_27 | AC | 162 ms
86,112 KB |
testcase_28 | AC | 328 ms
88,776 KB |
testcase_29 | AC | 64 ms
69,512 KB |
testcase_30 | AC | 138 ms
78,108 KB |
testcase_31 | TLE | - |
testcase_32 | AC | 44 ms
54,632 KB |
testcase_33 | AC | 45 ms
54,584 KB |
testcase_34 | AC | 73 ms
73,476 KB |
testcase_35 | AC | 44 ms
54,700 KB |
testcase_36 | AC | 44 ms
55,016 KB |
testcase_37 | AC | 44 ms
54,584 KB |
testcase_38 | AC | 44 ms
54,820 KB |
testcase_39 | WA | - |
testcase_40 | AC | 46 ms
61,240 KB |
ソースコード
import sys sys.setrecursionlimit(2 * 10**3) if sys.implementation.name == "pypy": import pypyjit pypyjit.set_param("max_unroll_recursion=-1") from collections import Counter, defaultdict class UnionFind: def __init__(self, N): self.N = N self.parent_or_size = [-1] * N self.group_count = N def root(self, x): if self.parent_or_size[x] < 0: return x else: self.parent_or_size[x] = self.root(self.parent_or_size[x]) return self.parent_or_size[x] def unite(self, x, y): root_x = self.root(x) root_y = self.root(y) if root_x == root_y: return if -self.parent_or_size[root_x] < -self.parent_or_size[root_y]: root_x, root_y = root_y, root_x self.parent_or_size[root_x] += self.parent_or_size[root_y] self.parent_or_size[root_y] = root_x self.group_count -= 1 def same(self, x, y): return self.root(x) == self.root(y) def size(self, x): return -self.parent_or_size[self.root(x)] def groups(self): ret = defaultdict(list) for i in range(self.N): ret[self.root(i)].append(i) return [group for group in ret.values()] input = lambda: sys.stdin.readline().rstrip() SHIFT = 20 MASK = (1 << SHIFT) - 1 def conv(x, y): return x << SHIFT | y def rev(pos): return pos >> SHIFT, pos & MASK H, W, N, D = map(int, input().split()) star = {} XY = [] for i in range(N): x, y = map(int, input().split()) XY.append((x, y)) star[conv(x, y)] = i MOVES = [] for xd in range(-D, D + 1): for yd in range(-D, D + 1): d = abs(xd) + abs(yd) if d > D: continue MOVES.append((xd, yd)) uf = UnionFind(N) cand = Counter() for i, (x, y) in enumerate(XY): for xd, yd in MOVES: d = abs(xd) + abs(yd) if d > D: continue xn = x + xd yn = y + yd if xn < 0 or yn < 0: continue posn = conv(xn, yn) cand[posn] += 1 if posn in star: uf.unite(i, star[posn]) stella = uf.groups() is_seiza = [0] * N count = 0 flag = 0 for block in stella: if len(block) > 1: count += 1 for i in block: is_seiza[i] = 1 else: flag = 1 mi = count ma = count + flag for pos in cand: x, y = rev(pos) seen = set() if cand[pos] == 1: continue for xd, yd in MOVES: d = abs(xd) + abs(yd) if d > D: continue xn = x + xd yn = y + yd posn = conv(xn, yn) if posn not in star: continue seen.add(uf.root(star[posn])) c = count + 1 for s in seen: if is_seiza[s]: c -= 1 mi = min(mi, c) ma = max(ma, c) print(mi, ma)