結果
問題 | No.2696 Sign Creation |
ユーザー | nikoro256 |
提出日時 | 2024-03-23 00:18:57 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,621 bytes |
コンパイル時間 | 319 ms |
コンパイル使用メモリ | 82,984 KB |
実行使用メモリ | 100,876 KB |
最終ジャッジ日時 | 2024-05-17 18:22:04 |
合計ジャッジ時間 | 14,536 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 49 ms
69,908 KB |
testcase_01 | AC | 49 ms
63,988 KB |
testcase_02 | AC | 42 ms
54,824 KB |
testcase_03 | AC | 46 ms
62,504 KB |
testcase_04 | AC | 44 ms
55,828 KB |
testcase_05 | AC | 47 ms
62,628 KB |
testcase_06 | AC | 43 ms
55,240 KB |
testcase_07 | AC | 43 ms
54,716 KB |
testcase_08 | AC | 142 ms
77,684 KB |
testcase_09 | AC | 68 ms
72,076 KB |
testcase_10 | AC | 133 ms
77,836 KB |
testcase_11 | AC | 80 ms
76,416 KB |
testcase_12 | AC | 81 ms
76,468 KB |
testcase_13 | AC | 1,211 ms
83,208 KB |
testcase_14 | AC | 483 ms
83,376 KB |
testcase_15 | AC | 454 ms
82,960 KB |
testcase_16 | AC | 1,126 ms
83,096 KB |
testcase_17 | AC | 386 ms
77,992 KB |
testcase_18 | AC | 246 ms
78,660 KB |
testcase_19 | AC | 492 ms
81,052 KB |
testcase_20 | AC | 105 ms
76,684 KB |
testcase_21 | AC | 376 ms
85,768 KB |
testcase_22 | AC | 458 ms
78,676 KB |
testcase_23 | AC | 437 ms
82,268 KB |
testcase_24 | AC | 454 ms
82,384 KB |
testcase_25 | AC | 637 ms
80,860 KB |
testcase_26 | AC | 406 ms
79,048 KB |
testcase_27 | AC | 395 ms
78,564 KB |
testcase_28 | AC | 308 ms
78,200 KB |
testcase_29 | AC | 421 ms
77,452 KB |
testcase_30 | AC | 378 ms
77,832 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): way=[] while True: if self.parents[x] < 0: break else: way.append(x) x=self.parents[x] for w in way: self.parents[w]=x return 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=[[-1]*W for _ in range(H)] 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+1): lim=D-abs(i) for j in range(-lim,lim+1): if (x+i,y+j) in datset: uf.union(dic[x][y],dic[x+i][y+j]) 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): lim=D-abs(k) for t in range(-lim,lim+1): tmp=(i+k,j+t) if tmp in datset: use.add(uf.find(dic[i+k][j+t])) flag=False one=0 notone=0 tmp=0 for u in use: if -uf.parents[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)