結果
問題 | No.2696 Sign Creation |
ユーザー | nikoro256 |
提出日時 | 2024-03-22 23:19:29 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,622 bytes |
コンパイル時間 | 151 ms |
コンパイル使用メモリ | 82,552 KB |
実行使用メモリ | 128,700 KB |
最終ジャッジ日時 | 2024-05-17 18:20:05 |
合計ジャッジ時間 | 14,756 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 46 ms
71,516 KB |
testcase_01 | AC | 45 ms
63,148 KB |
testcase_02 | AC | 37 ms
55,128 KB |
testcase_03 | AC | 47 ms
63,868 KB |
testcase_04 | AC | 45 ms
62,764 KB |
testcase_05 | AC | 50 ms
64,452 KB |
testcase_06 | AC | 40 ms
56,092 KB |
testcase_07 | AC | 41 ms
55,048 KB |
testcase_08 | AC | 168 ms
79,176 KB |
testcase_09 | AC | 92 ms
76,688 KB |
testcase_10 | AC | 136 ms
77,960 KB |
testcase_11 | AC | 87 ms
76,924 KB |
testcase_12 | AC | 87 ms
76,664 KB |
testcase_13 | AC | 1,136 ms
90,392 KB |
testcase_14 | AC | 502 ms
90,948 KB |
testcase_15 | AC | 478 ms
89,832 KB |
testcase_16 | AC | 1,162 ms
89,424 KB |
testcase_17 | AC | 429 ms
77,256 KB |
testcase_18 | AC | 275 ms
79,216 KB |
testcase_19 | AC | 542 ms
86,312 KB |
testcase_20 | AC | 129 ms
77,272 KB |
testcase_21 | AC | 406 ms
96,088 KB |
testcase_22 | AC | 470 ms
79,264 KB |
testcase_23 | AC | 435 ms
88,412 KB |
testcase_24 | AC | 433 ms
88,272 KB |
testcase_25 | AC | 686 ms
85,152 KB |
testcase_26 | AC | 459 ms
79,108 KB |
testcase_27 | AC | 478 ms
77,916 KB |
testcase_28 | AC | 351 ms
78,292 KB |
testcase_29 | AC | 441 ms
77,332 KB |
testcase_30 | AC | 419 ms
77,976 KB |
testcase_31 | TLE | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
testcase_40 | -- | - |
ソースコード
from collections import defaultdict class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): group_members = defaultdict(list) for member in range(self.n): group_members[self.find(member)].append(member) return group_members def __str__(self): return '\n'.join(f'{r}: {m}' for r, m in self.all_group_members().items()) import sys input=sys.stdin.readline H,W,N,D=map(int,input().split()) dat=[] datset=set() dic={} uf=UnionFind(N) for i in range(N): x,y=map(int,input().split()) x-=1 y-=1 dat.append((x,y)) datset.add((x,y)) dic[(x,y)]=i for x,y in dat: for i in range(-D,D+1): for j in range(-D,D+1): if abs(i)+abs(j)>D: continue if (x+i,y+j) in datset: uf.union(dic[(x,y)],dic[(x+i,y+j)]) root={} for a in datset: root[a]=uf.find(dic[a]) small=10**9 big=-10**9 for i in range(H): for j in range(W): use=set() for k in range(-D,D+1): for t in range(-D,D+1): if abs(k)+abs(t)>D: continue tmp=(i+k,j+t) if tmp in datset: use.add(root[tmp]) flag=False one=0 notone=0 tmp=0 for u in use: if uf.size(u)==1: one+=1 else: notone+=1 if notone==0: if one>0: tmp+=1 else: tmp=-(notone-1) big=max(big,tmp) small=min(small,tmp) all=0 #print(small,big) for idx,lis in uf.all_group_members().items(): if len(lis)>1: all+=1 #print(all) print(all+small,all+big)