結果
問題 | No.2696 Sign Creation |
ユーザー | mkawa2 |
提出日時 | 2024-03-22 23:14:32 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,717 bytes |
コンパイル時間 | 137 ms |
コンパイル使用メモリ | 82,596 KB |
実行使用メモリ | 178,184 KB |
最終ジャッジ日時 | 2024-05-17 18:19:19 |
合計ジャッジ時間 | 10,691 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
56,172 KB |
testcase_01 | AC | 39 ms
55,252 KB |
testcase_02 | AC | 37 ms
55,208 KB |
testcase_03 | AC | 37 ms
55,520 KB |
testcase_04 | AC | 38 ms
55,404 KB |
testcase_05 | AC | 37 ms
56,160 KB |
testcase_06 | AC | 37 ms
55,248 KB |
testcase_07 | AC | 38 ms
54,884 KB |
testcase_08 | AC | 147 ms
80,404 KB |
testcase_09 | AC | 39 ms
56,352 KB |
testcase_10 | AC | 136 ms
79,820 KB |
testcase_11 | AC | 39 ms
54,692 KB |
testcase_12 | AC | 37 ms
55,704 KB |
testcase_13 | AC | 695 ms
178,184 KB |
testcase_14 | AC | 390 ms
128,120 KB |
testcase_15 | AC | 421 ms
126,208 KB |
testcase_16 | AC | 849 ms
171,064 KB |
testcase_17 | AC | 40 ms
56,824 KB |
testcase_18 | AC | 125 ms
84,184 KB |
testcase_19 | AC | 345 ms
125,524 KB |
testcase_20 | AC | 42 ms
62,508 KB |
testcase_21 | AC | 382 ms
114,056 KB |
testcase_22 | AC | 110 ms
84,068 KB |
testcase_23 | AC | 324 ms
113,628 KB |
testcase_24 | AC | 319 ms
113,268 KB |
testcase_25 | AC | 341 ms
133,256 KB |
testcase_26 | AC | 55 ms
69,044 KB |
testcase_27 | AC | 85 ms
78,404 KB |
testcase_28 | AC | 83 ms
78,476 KB |
testcase_29 | AC | 44 ms
62,604 KB |
testcase_30 | AC | 49 ms
66,260 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.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() ij=LLI1(n) ij2u={(i,j):u for u,(i,j) in enumerate(ij)} uf=UnionFind(n) # can=set() ne=[[] for _ in range(n)] 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)): ne[u].append((x,y)) if (x,y) in ij2u: v=ij2u[x,y] uf.merge(u,v) # else: # can.add((x,y)) one=[] cnt=Counter() s=0 for uu in uf.mem: if not uu:continue if len(uu)==1: one.append(uu[0]) else: s+=1 xy = set() for u in uu: for x,y in ne[u]:xy.add(x*w+y) for v in xy:cnt[v]+=1 def inc(): for u in one: i, j = ij[u] 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*w+y not in cnt:return 1 return 0 mn=s if cnt:mn=s-max(cnt.values())+1 mx=s+inc() print(mn,mx)