結果

問題 No.2696 Sign Creation
ユーザー ニックネームニックネーム
提出日時 2024-03-22 22:52:26
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 328 ms / 2,500 ms
コード長 1,278 bytes
コンパイル時間 153 ms
コンパイル使用メモリ 82,528 KB
実行使用メモリ 79,544 KB
最終ジャッジ日時 2024-05-17 18:17:00
合計ジャッジ時間 6,419 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
60,428 KB
testcase_01 AC 37 ms
58,832 KB
testcase_02 AC 37 ms
53,488 KB
testcase_03 AC 36 ms
53,608 KB
testcase_04 AC 41 ms
53,744 KB
testcase_05 AC 35 ms
54,376 KB
testcase_06 AC 34 ms
53,552 KB
testcase_07 AC 34 ms
53,964 KB
testcase_08 AC 108 ms
77,688 KB
testcase_09 AC 55 ms
71,508 KB
testcase_10 AC 129 ms
77,792 KB
testcase_11 AC 77 ms
76,076 KB
testcase_12 AC 77 ms
76,280 KB
testcase_13 AC 328 ms
78,884 KB
testcase_14 AC 238 ms
79,060 KB
testcase_15 AC 246 ms
79,448 KB
testcase_16 AC 304 ms
78,612 KB
testcase_17 AC 139 ms
77,216 KB
testcase_18 AC 198 ms
78,796 KB
testcase_19 AC 257 ms
79,248 KB
testcase_20 AC 83 ms
76,316 KB
testcase_21 AC 223 ms
79,256 KB
testcase_22 AC 223 ms
79,312 KB
testcase_23 AC 252 ms
78,708 KB
testcase_24 AC 239 ms
78,600 KB
testcase_25 AC 291 ms
78,960 KB
testcase_26 AC 169 ms
78,308 KB
testcase_27 AC 173 ms
78,360 KB
testcase_28 AC 172 ms
78,772 KB
testcase_29 AC 140 ms
77,212 KB
testcase_30 AC 186 ms
78,072 KB
testcase_31 AC 314 ms
79,544 KB
testcase_32 AC 42 ms
59,288 KB
testcase_33 AC 55 ms
68,548 KB
testcase_34 AC 39 ms
58,856 KB
testcase_35 AC 34 ms
52,944 KB
testcase_36 AC 34 ms
52,868 KB
testcase_37 AC 35 ms
53,980 KB
testcase_38 AC 36 ms
52,848 KB
testcase_39 AC 35 ms
52,464 KB
testcase_40 AC 35 ms
53,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class UF:
    def __init__(self,n):
        self.p = [-1]*n
    def f(self,x):
        if self.p[x]<0: return x
        else: self.p[x] = self.f(self.p[x]); return self.p[x]
    def u(self,x,y):
        x = self.f(x); y = self.f(y)
        if x==y: return
        if -self.p[x]<-self.p[y]: x,y = y,x
        self.p[x] += self.p[y]; self.p[y] = x
    def n(self,x): return -self.p[self.f(x)]
h,w,n,d = map(int,input().split())
a = [[-1]*w for _ in range(h)]
for i in range(n):
    x,y = map(int,input().split())
    a[x-1][y-1] = i
uf = UF(n)
for i in range(h):
    for j in range(w):
        if a[i][j]<0: continue
        for x in range(max(i-d,0),min(i+d+1,h)):
            for y in range(max(j-(d-abs(i-x)),0),min(j+(d-abs(i-x))+1,w)):
                if a[x][y]>=0: uf.u(a[i][j],a[x][y])
c = len({uf.f(i) for i in range(n) if uf.n(i)>1}); l = n; r = 0
for i in range(h):
    for j in range(w):
        if a[i][j]>=0: continue
        s = set(); t = 0
        for x in range(max(i-d,0),min(i+d+1,h)):
            for y in range(max(j-(d-abs(i-x)),0),min(j+(d-abs(i-x))+1,w)):
                if a[x][y]<0: continue
                if uf.n(a[x][y])>1: s.add(uf.f(a[x][y]))
                else: t = 1
        b = c-len(s)+1 if s else c+t; l = min(l,b); r = max(r,b)
print(l,r)
0