結果

問題 No.2696 Sign Creation
ユーザー sasa8uyauyasasa8uyauya
提出日時 2024-03-23 05:09:01
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,027 bytes
コンパイル時間 143 ms
コンパイル使用メモリ 82,564 KB
実行使用メモリ 112,308 KB
最終ジャッジ日時 2024-05-17 18:22:49
合計ジャッジ時間 14,094 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
68,488 KB
testcase_01 WA -
testcase_02 AC 38 ms
53,000 KB
testcase_03 AC 46 ms
61,216 KB
testcase_04 AC 43 ms
59,944 KB
testcase_05 AC 43 ms
60,224 KB
testcase_06 AC 38 ms
53,408 KB
testcase_07 WA -
testcase_08 AC 172 ms
78,184 KB
testcase_09 WA -
testcase_10 AC 149 ms
77,880 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 1,428 ms
88,256 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 1,952 ms
92,828 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 299 ms
77,768 KB
testcase_31 TLE -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

h,w,n,d=map(int,input().split())
a=[[-1]*w for i in range(h)]
s=[]
r=list(range(n))
v=[1]*n

def union(x,y):
  rx=root(x)
  ry=root(y)
  if rx>ry:
    rx,ry=ry,rx
  r[ry]=rx
  v[rx]+=v[ry]
  return

def root(x):
  p=x
  l=[p]
  while r[p]!=p:
    p=r[p]
    l.append(p)
  for p in l:
    r[p]=l[-1]
  return r[x]

for i in range(n):
	x,y=map(int,input().split())
	x-=1
	y-=1
	a[x][y]=i
	s+=[(x,y)]
	for dx in range(-d,d+1):
		for dy in range(-d,d+1):
			xx=x+dx
			yy=y+dy
			if 0<=xx<h and 0<=yy<w and abs(dx)+abs(dy)<=d and a[xx][yy]!=-1:
				union(i,a[xx][yy])
for i in range(n):
	x,y=s[i]
	a[x][y]=root(i)
g0=len(set(r))
g1=g0
g2=g0
for x in range(h):
	for y in range(w):
		if a[x][y]==-1:
			rr=[]
			f=0
			for dx in range(-d,d+1):
				for dy in range(-d,d+1):
					xx=x+dx
					yy=y+dy
					if 0<=xx<h and 0<=yy<w and abs(dx)+abs(dy)<=d and a[xx][yy]!=-1:
						if v[a[xx][yy]]>1:
							rr+=[a[xx][yy]]
						else:
							f=1
			rr=set(rr)
			if len(rr)==0:
				g1=g0+f
			else:
				g2=min(g2,g0-len(rr)+1)
print(g2,g1)
0