結果
問題 | No.2696 Sign Creation |
ユーザー | mkawa2 |
提出日時 | 2024-03-22 22:48:51 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,575 bytes |
コンパイル時間 | 168 ms |
コンパイル使用メモリ | 82,308 KB |
実行使用メモリ | 95,168 KB |
最終ジャッジ日時 | 2024-05-17 18:16:38 |
合計ジャッジ時間 | 15,544 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 45 ms
63,844 KB |
testcase_01 | AC | 45 ms
55,732 KB |
testcase_02 | AC | 44 ms
54,296 KB |
testcase_03 | AC | 45 ms
55,928 KB |
testcase_04 | AC | 46 ms
56,388 KB |
testcase_05 | AC | 45 ms
55,132 KB |
testcase_06 | AC | 49 ms
55,604 KB |
testcase_07 | AC | 48 ms
56,180 KB |
testcase_08 | AC | 177 ms
78,936 KB |
testcase_09 | AC | 65 ms
67,896 KB |
testcase_10 | AC | 185 ms
78,976 KB |
testcase_11 | AC | 69 ms
70,752 KB |
testcase_12 | AC | 68 ms
70,092 KB |
testcase_13 | AC | 1,718 ms
91,320 KB |
testcase_14 | AC | 668 ms
93,148 KB |
testcase_15 | AC | 648 ms
91,556 KB |
testcase_16 | AC | 1,592 ms
90,060 KB |
testcase_17 | AC | 67 ms
69,676 KB |
testcase_18 | AC | 310 ms
86,356 KB |
testcase_19 | AC | 687 ms
91,056 KB |
testcase_20 | AC | 84 ms
76,700 KB |
testcase_21 | AC | 459 ms
92,392 KB |
testcase_22 | AC | 365 ms
86,700 KB |
testcase_23 | AC | 588 ms
92,172 KB |
testcase_24 | AC | 577 ms
91,868 KB |
testcase_25 | AC | 840 ms
90,856 KB |
testcase_26 | AC | 150 ms
77,856 KB |
testcase_27 | AC | 444 ms
92,668 KB |
testcase_28 | AC | 397 ms
95,168 KB |
testcase_29 | AC | 102 ms
76,620 KB |
testcase_30 | AC | 114 ms
77,476 KB |
testcase_31 | TLE | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
testcase_40 | -- | - |
ソースコード
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._tree = [-1]*n # number of connected component self.cnt = n def root(self, u): stack = [] while self._tree[u] >= 0: stack.append(u) u = self._tree[u] for v in stack: self._tree[v] = u return u def same(self, u, v): return self.root(u) == self.root(v) def merge(self, u, v): u, v = self.root(u), self.root(v) if u == v: return False if self._tree[u] > self._tree[v]: u, v = v, u self._tree[u] += self._tree[v] self._tree[v] = u self.cnt -= 1 return True # size of connected component def size(self, u): return -self._tree[self.root(u)] from collections import Counter h,w,n,d=LI() ij=LLI1(n) ij2u={(i,j):u for u,(i,j) in enumerate(ij)} uf=UnionFind(n) can=set() for u,(i,j) in enumerate(ij): 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)): if (x,y) in ij2u: v=ij2u[x,y] uf.merge(u,v) else: can.add((x,y)) rr=set() for u in range(n): r=uf.root(u) if uf.size(r)>1: rr.add(r) s=len(rr) mn,mx=inf,-inf for i,j in can: ne=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)): if (x,y) in ij2u: u=ij2u[x,y] u=uf.root(u) if uf.size(u)==1: one=1 else: ne.add(u) if ne: cur=s-len(ne)+1 elif one: cur=s+1 else: cur=s mn=min(mn,cur) mx=max(mx,cur) print(mn,mx)