結果

問題 No.2696 Sign Creation
ユーザー sasa8uyauyasasa8uyauya
提出日時 2024-03-23 10:45:01
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,034 bytes
コンパイル時間 483 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 108,248 KB
最終ジャッジ日時 2024-03-23 10:45:06
合計ジャッジ時間 5,777 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
59,460 KB
testcase_01 AC 41 ms
59,460 KB
testcase_02 AC 37 ms
53,460 KB
testcase_03 AC 41 ms
59,460 KB
testcase_04 WA -
testcase_05 AC 42 ms
59,716 KB
testcase_06 AC 37 ms
53,460 KB
testcase_07 AC 37 ms
53,460 KB
testcase_08 WA -
testcase_09 AC 53 ms
64,192 KB
testcase_10 WA -
testcase_11 AC 62 ms
66,424 KB
testcase_12 AC 61 ms
66,424 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

h,w,n,d=map(int,input().split())
a=[[-1]*w for i in range(h)]
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]

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