結果

問題 No.2696 Sign Creation
ユーザー ニックネームニックネーム
提出日時 2024-03-22 22:52:26
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 383 ms / 2,500 ms
コード長 1,278 bytes
コンパイル時間 169 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 78,956 KB
最終ジャッジ日時 2024-03-27 17:59:05
合計ジャッジ時間 7,304 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
59,852 KB
testcase_01 AC 43 ms
59,468 KB
testcase_02 AC 38 ms
53,460 KB
testcase_03 AC 39 ms
53,460 KB
testcase_04 AC 39 ms
53,460 KB
testcase_05 AC 39 ms
53,460 KB
testcase_06 AC 43 ms
53,460 KB
testcase_07 AC 39 ms
53,460 KB
testcase_08 AC 125 ms
76,864 KB
testcase_09 AC 64 ms
70,552 KB
testcase_10 AC 149 ms
77,240 KB
testcase_11 AC 86 ms
75,828 KB
testcase_12 AC 87 ms
75,828 KB
testcase_13 AC 383 ms
78,188 KB
testcase_14 AC 278 ms
78,316 KB
testcase_15 AC 290 ms
78,920 KB
testcase_16 AC 351 ms
77,932 KB
testcase_17 AC 150 ms
76,824 KB
testcase_18 AC 231 ms
78,396 KB
testcase_19 AC 296 ms
78,692 KB
testcase_20 AC 92 ms
75,968 KB
testcase_21 AC 257 ms
78,704 KB
testcase_22 AC 247 ms
78,540 KB
testcase_23 AC 286 ms
78,316 KB
testcase_24 AC 268 ms
78,492 KB
testcase_25 AC 309 ms
78,924 KB
testcase_26 AC 192 ms
77,584 KB
testcase_27 AC 203 ms
77,856 KB
testcase_28 AC 193 ms
77,844 KB
testcase_29 AC 157 ms
76,728 KB
testcase_30 AC 217 ms
77,296 KB
testcase_31 AC 351 ms
78,956 KB
testcase_32 AC 41 ms
59,468 KB
testcase_33 AC 61 ms
68,344 KB
testcase_34 AC 43 ms
58,932 KB
testcase_35 AC 38 ms
53,460 KB
testcase_36 AC 38 ms
53,460 KB
testcase_37 AC 37 ms
53,460 KB
testcase_38 AC 37 ms
53,460 KB
testcase_39 AC 38 ms
53,460 KB
testcase_40 AC 39 ms
53,460 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