結果

問題 No.2696 Sign Creation
ユーザー 👑 timitimi
提出日時 2024-02-03 04:15:32
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 324 ms / 2,500 ms
コード長 1,501 bytes
コンパイル時間 174 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 83,112 KB
最終ジャッジ日時 2024-03-27 17:57:22
合計ジャッジ時間 6,573 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
59,968 KB
testcase_01 AC 42 ms
59,968 KB
testcase_02 AC 37 ms
53,460 KB
testcase_03 AC 41 ms
59,456 KB
testcase_04 AC 38 ms
53,460 KB
testcase_05 AC 42 ms
59,456 KB
testcase_06 AC 38 ms
53,460 KB
testcase_07 AC 38 ms
53,460 KB
testcase_08 AC 103 ms
76,348 KB
testcase_09 AC 52 ms
64,440 KB
testcase_10 AC 111 ms
76,736 KB
testcase_11 AC 61 ms
66,520 KB
testcase_12 AC 61 ms
66,520 KB
testcase_13 AC 324 ms
81,772 KB
testcase_14 AC 248 ms
82,212 KB
testcase_15 AC 228 ms
81,028 KB
testcase_16 AC 292 ms
80,240 KB
testcase_17 AC 145 ms
80,248 KB
testcase_18 AC 161 ms
82,496 KB
testcase_19 AC 227 ms
82,492 KB
testcase_20 AC 68 ms
68,608 KB
testcase_21 AC 241 ms
81,708 KB
testcase_22 AC 214 ms
82,940 KB
testcase_23 AC 242 ms
82,436 KB
testcase_24 AC 249 ms
83,028 KB
testcase_25 AC 247 ms
82,340 KB
testcase_26 AC 164 ms
83,112 KB
testcase_27 AC 197 ms
81,420 KB
testcase_28 AC 171 ms
82,324 KB
testcase_29 AC 153 ms
80,128 KB
testcase_30 AC 157 ms
80,156 KB
testcase_31 AC 280 ms
79,852 KB
testcase_32 AC 41 ms
59,456 KB
testcase_33 AC 51 ms
64,336 KB
testcase_34 AC 47 ms
61,964 KB
testcase_35 AC 36 ms
53,460 KB
testcase_36 AC 37 ms
53,460 KB
testcase_37 AC 37 ms
53,460 KB
testcase_38 AC 37 ms
53,460 KB
testcase_39 AC 37 ms
53,460 KB
testcase_40 AC 36 ms
53,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

H,W,N,D=map(int, input().split())
A=[[-1]*W for _ in range(H)]

for i in range(N):
  h,w=map(int, input().split())
  h-=1;w-=1
  A[h][w]=i
  
B=[]
for i in range(-D,D+1):
  for j in range(-D,D+1):
    if abs(i)+abs(j)<=D:
      B.append((i,j))
      
par=[i for i in range(N)];rank=[0]*N;size=[1]*N
def find(x):
  if par[x]==x:
    return x
  else:
    par[x]=find(par[x])
    return par[x]
 
#同じ集合か判定
def same(x,y):
  return find(x)==find(y)
 
def union(x,y):
  x=find(x)
  y=find(y)
  if x==y:
    return 
  if rank[x]>rank[y]:
    par[y]=x
    size[x]+=size[y]
  else:
    par[x]=y
    size[y]+=size[x]
    if rank[x]==rank[y]:
      rank[y]+=1
 
for h in range(H):
  for w in range(W):
    if A[h][w]==-1:
      continue 
    p=A[h][w]
    for x,y in B:
      nh,nw=h+x,w+y
      if 0<=nh<H and 0<=nw<W and A[nh][nw]!=-1:
        q=A[nh][nw]
        union(p,q)
        
D={};E={};F={}
for i in range(N):
  d=find(i)
  if d not in F:
    F[d]=1
    if size[d]==1:
      D[d]=1
    else:
      E[d]=1
      
al=len(E);ans=[]
for h in range(H):
  for w in range(W):
    if A[h][w]!=-1:
      continue
    DD,EE=set(),set()
    for x,y in B:
      nh,nw=h+x,w+y
      if 0<=nh<H and 0<=nw<W and A[nh][nw]!=-1:
        q=find(A[nh][nw])
        if size[q]==1:
          EE.add(q)
        else:
          DD.add(q)
    if len(EE)==0:
      if len(DD)==0:
        ans.append(al)
      else:
        ans.append(al-len(DD)+1)
    else:
      ans.append(al-len(DD)+1)

print(min(ans),max(ans))
0