結果

問題 No.2696 Sign Creation
ユーザー sasa8uyauyasasa8uyauya
提出日時 2024-03-23 05:44:19
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,040 bytes
コンパイル時間 361 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 107,332 KB
最終ジャッジ日時 2024-03-23 05:44:33
合計ジャッジ時間 13,020 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
66,264 KB
testcase_01 AC 43 ms
59,460 KB
testcase_02 AC 38 ms
53,460 KB
testcase_03 AC 43 ms
59,460 KB
testcase_04 AC 42 ms
53,460 KB
testcase_05 AC 44 ms
59,716 KB
testcase_06 AC 39 ms
53,460 KB
testcase_07 AC 38 ms
53,460 KB
testcase_08 AC 135 ms
76,604 KB
testcase_09 AC 51 ms
61,980 KB
testcase_10 AC 154 ms
76,920 KB
testcase_11 AC 57 ms
64,056 KB
testcase_12 AC 64 ms
64,056 KB
testcase_13 AC 1,474 ms
84,616 KB
testcase_14 AC 280 ms
81,128 KB
testcase_15 AC 278 ms
80,744 KB
testcase_16 AC 2,132 ms
88,084 KB
testcase_17 AC 112 ms
72,440 KB
testcase_18 AC 156 ms
77,756 KB
testcase_19 AC 267 ms
79,448 KB
testcase_20 AC 71 ms
66,144 KB
testcase_21 AC 224 ms
81,352 KB
testcase_22 AC 171 ms
77,488 KB
testcase_23 AC 258 ms
80,024 KB
testcase_24 AC 247 ms
80,024 KB
testcase_25 AC 326 ms
79,684 KB
testcase_26 AC 135 ms
76,840 KB
testcase_27 AC 172 ms
77,140 KB
testcase_28 AC 174 ms
77,428 KB
testcase_29 AC 147 ms
72,968 KB
testcase_30 AC 136 ms
76,584 KB
testcase_31 TLE -
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)]
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]

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
	s+=[(x,y)]
	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(i,a[xx][yy])
for i in range(n):
	x,y=s[i]
	a[x][y]=root(i)
g0=len(set([r[i] for i in range(n) if v[i]>1]))
g1=g0
g2=g0
for x in range(h):
	for y in range(w):
		if a[x][y]==-1:
			rr=set()
			f=0
			for dx,dy in dxdy:
				xx=x+dx
				yy=y+dy
				if 0<=xx<h and 0<=yy<w and a[xx][yy]!=-1:
					if v[a[xx][yy]]>1:
						rr.add(a[xx][yy])
					else:
						f=1
			if len(rr)==0:
				g1=max(g1,g0+f)
			else:
				g2=min(g2,g0-len(rr)+1)
print(g2,g1)
0