結果
| 問題 |
No.2696 Sign Creation
|
| コンテスト | |
| ユーザー |
ゼット
|
| 提出日時 | 2024-03-22 22:21:52 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,716 bytes |
| コンパイル時間 | 325 ms |
| コンパイル使用メモリ | 82,280 KB |
| 実行使用メモリ | 152,392 KB |
| 最終ジャッジ日時 | 2024-12-20 12:03:45 |
| 合計ジャッジ時間 | 14,110 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 37 TLE * 1 |
ソースコード
class unif:
def __init__(self,n):
self.pare=[-1]*n
self.size=[1]*n
def root(self,x):
while self.pare[x]!=-1:
x=self.pare[x]
return x
def unite(self,u,v):
rootu=self.root(u)
rootv=self.root(v)
if rootu!=rootv:
if self.size[rootu]>=self.size[rootv]:
self.pare[rootv]=rootu
self.size[rootu]+=self.size[rootv]
else:
self.pare[rootu]=rootv
self.size[rootv]+=self.size[rootu]
def same(self,s,t):
return self.root(s)==self.root(t)
H,W,N,D=map(int,input().split())
C=set()
A=[set() for i in range(H+1)]
T={}
L=[]
for i in range(N):
x,y=map(int,input().split())
L.append((x,y))
T[x*10**10+y]=i
Z=unif(N)
for i in range(N):
x,y=L[i][:]
for dx in range(-D,D+1):
k=D-abs(dx)
for dy in range(-k,k+1):
x2,y2=x+dx,y+dy
if x==x2 and y==y2:
continue
if x2<=0 or x2>=H+1 or y2<=0 or y2>=W+1:
continue
A[x2].add(y2)
w=x2*10**10+y2
if w in T:
pos=T[w]
Z.unite(i,pos)
count=0
b=set()
for i in range(N):
p=Z.root(i)
if Z.size[p]>1:
b.add(Z.root(i))
count=len(b)
h=[]
for x in range(1,H+1):
if len(A[x])!=W:
h.append(count)
for y in A[x]:
c=0
B=set()
for dx in range(-D,D+1):
k=D-abs(dx)
for dy in range(-k,k+1):
x2,y2=x+dx,y+dy
if x==x2 and y==y2:
continue
if x2<=0 or x2>=H+1 or y2<=0 or y2>=W+1:
continue
w=x2*10**10+y2
if w in T:
pos=T[w]
p=Z.root(pos)
if Z.size[p]==1:
c=1
else:
B.add(p)
if c==1 and len(B)==0:
r=1
else:
r=1-len(B)
h.append(count+r)
print(min(h),max(h))
ゼット