結果

問題 No.2696 Sign Creation
ユーザー ゼットゼット
提出日時 2024-03-22 22:31:34
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,897 bytes
コンパイル時間 314 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 104,796 KB
最終ジャッジ日時 2024-03-22 22:31:47
合計ジャッジ時間 12,202 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
60,264 KB
testcase_01 AC 39 ms
53,460 KB
testcase_02 AC 39 ms
53,460 KB
testcase_03 AC 43 ms
59,464 KB
testcase_04 AC 40 ms
53,460 KB
testcase_05 AC 44 ms
59,720 KB
testcase_06 AC 39 ms
53,460 KB
testcase_07 AC 41 ms
53,460 KB
testcase_08 AC 161 ms
77,076 KB
testcase_09 AC 64 ms
68,456 KB
testcase_10 AC 152 ms
77,056 KB
testcase_11 AC 60 ms
66,360 KB
testcase_12 AC 64 ms
66,360 KB
testcase_13 AC 909 ms
87,872 KB
testcase_14 AC 482 ms
87,736 KB
testcase_15 AC 392 ms
85,304 KB
testcase_16 AC 835 ms
85,068 KB
testcase_17 AC 69 ms
70,520 KB
testcase_18 AC 251 ms
79,572 KB
testcase_19 AC 457 ms
86,356 KB
testcase_20 AC 73 ms
72,612 KB
testcase_21 AC 357 ms
86,860 KB
testcase_22 AC 289 ms
78,496 KB
testcase_23 AC 395 ms
85,996 KB
testcase_24 AC 377 ms
85,356 KB
testcase_25 AC 555 ms
84,588 KB
testcase_26 AC 161 ms
77,080 KB
testcase_27 AC 315 ms
78,744 KB
testcase_28 AC 258 ms
80,004 KB
testcase_29 AC 87 ms
72,856 KB
testcase_30 AC 99 ms
75,796 KB
testcase_31 TLE -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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(p)
count=len(b)
h=[]
u=[0]*N
t=[0]*N
for i in range(N):
  p=Z.root(i)
  k=Z.size[p]
  u[i]=p
  t[i]=k
ans1=10**10
ans2=-10**10
for x in range(1,H+1):
  if len(A[x])!=W:
    ans1=min(ans1,count)
    ans2=max(ans2,count)
  for y in A[x]:
    w=x*10**10+y
    if w in T:
      continue
    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]
          if t[pos]==1:
            c=1
          else:
            B.add(u[pos])
    if c==1 and len(B)==0:
      r=1
    else:
      r=1-len(B)
    ans1=min(ans1,r+count)
    ans2=max(ans2,r+count)
print(ans1,ans2)
0