結果
問題 | No.2696 Sign Creation |
ユーザー | mo124121 |
提出日時 | 2024-02-04 09:56:32 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 2,764 bytes |
コンパイル時間 | 446 ms |
コンパイル使用メモリ | 82,024 KB |
実行使用メモリ | 96,140 KB |
最終ジャッジ日時 | 2024-12-20 11:52:11 |
合計ジャッジ時間 | 18,670 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 44 ms
63,264 KB |
testcase_01 | AC | 44 ms
55,756 KB |
testcase_02 | AC | 53 ms
63,004 KB |
testcase_03 | AC | 61 ms
67,648 KB |
testcase_04 | AC | 54 ms
62,824 KB |
testcase_05 | AC | 64 ms
68,736 KB |
testcase_06 | AC | 45 ms
55,880 KB |
testcase_07 | AC | 43 ms
55,248 KB |
testcase_08 | AC | 212 ms
77,824 KB |
testcase_09 | AC | 69 ms
73,596 KB |
testcase_10 | AC | 152 ms
78,004 KB |
testcase_11 | AC | 88 ms
76,964 KB |
testcase_12 | AC | 87 ms
76,852 KB |
testcase_13 | AC | 2,196 ms
96,140 KB |
testcase_14 | AC | 678 ms
93,948 KB |
testcase_15 | AC | 733 ms
91,548 KB |
testcase_16 | AC | 2,051 ms
92,748 KB |
testcase_17 | AC | 89 ms
76,872 KB |
testcase_18 | AC | 330 ms
82,532 KB |
testcase_19 | AC | 775 ms
92,096 KB |
testcase_20 | AC | 104 ms
77,208 KB |
testcase_21 | AC | 483 ms
95,588 KB |
testcase_22 | AC | 538 ms
83,364 KB |
testcase_23 | AC | 634 ms
94,384 KB |
testcase_24 | AC | 640 ms
93,592 KB |
testcase_25 | AC | 1,035 ms
91,460 KB |
testcase_26 | AC | 212 ms
78,508 KB |
testcase_27 | AC | 644 ms
84,984 KB |
testcase_28 | AC | 538 ms
86,972 KB |
testcase_29 | AC | 121 ms
76,928 KB |
testcase_30 | AC | 137 ms
77,780 KB |
testcase_31 | TLE | - |
testcase_32 | AC | 44 ms
55,752 KB |
testcase_33 | AC | 43 ms
55,240 KB |
testcase_34 | AC | 80 ms
77,220 KB |
testcase_35 | AC | 45 ms
54,924 KB |
testcase_36 | AC | 45 ms
55,172 KB |
testcase_37 | AC | 43 ms
54,732 KB |
testcase_38 | AC | 44 ms
54,300 KB |
testcase_39 | WA | - |
testcase_40 | AC | 44 ms
61,724 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 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 = set() 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 cand.add(conv(xn, yn)) posn = conv(xn, yn) if posn in star: uf.unite(i, star[posn]) stella = uf.groups() is_seiza = [0] * N count = 0 for block in stella: if len(block) > 1: count += 1 for i in block: is_seiza[i] = 1 mi = count ma = count for pos in cand: x, y = rev(pos) seen = set() 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)