結果

問題 No.2696 Sign Creation
ユーザー mymelochanmymelochan
提出日時 2024-03-22 22:13:29
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 690 ms / 2,500 ms
コード長 2,569 bytes
コンパイル時間 150 ms
コンパイル使用メモリ 82,692 KB
実行使用メモリ 93,976 KB
最終ジャッジ日時 2024-05-17 18:11:27
合計ジャッジ時間 9,902 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
63,996 KB
testcase_01 AC 48 ms
64,976 KB
testcase_02 AC 40 ms
56,568 KB
testcase_03 AC 47 ms
64,168 KB
testcase_04 AC 44 ms
62,320 KB
testcase_05 AC 45 ms
63,484 KB
testcase_06 AC 41 ms
56,212 KB
testcase_07 AC 41 ms
55,740 KB
testcase_08 AC 176 ms
78,884 KB
testcase_09 AC 80 ms
76,280 KB
testcase_10 AC 181 ms
79,168 KB
testcase_11 AC 102 ms
76,872 KB
testcase_12 AC 100 ms
76,820 KB
testcase_13 AC 550 ms
84,760 KB
testcase_14 AC 471 ms
84,944 KB
testcase_15 AC 424 ms
85,128 KB
testcase_16 AC 524 ms
84,308 KB
testcase_17 AC 265 ms
78,328 KB
testcase_18 AC 268 ms
80,084 KB
testcase_19 AC 419 ms
82,556 KB
testcase_20 AC 125 ms
78,176 KB
testcase_21 AC 345 ms
85,920 KB
testcase_22 AC 375 ms
80,096 KB
testcase_23 AC 455 ms
84,584 KB
testcase_24 AC 452 ms
84,328 KB
testcase_25 AC 455 ms
82,512 KB
testcase_26 AC 293 ms
79,192 KB
testcase_27 AC 323 ms
79,808 KB
testcase_28 AC 287 ms
80,168 KB
testcase_29 AC 292 ms
79,024 KB
testcase_30 AC 292 ms
78,748 KB
testcase_31 AC 690 ms
93,976 KB
testcase_32 AC 51 ms
66,504 KB
testcase_33 AC 85 ms
77,076 KB
testcase_34 AC 54 ms
67,872 KB
testcase_35 AC 40 ms
55,496 KB
testcase_36 AC 39 ms
55,924 KB
testcase_37 AC 40 ms
56,888 KB
testcase_38 AC 40 ms
56,544 KB
testcase_39 AC 37 ms
55,252 KB
testcase_40 AC 38 ms
55,672 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#############################################################

import sys
sys.setrecursionlimit(10**7)

from heapq import heappop,heappush
from collections import deque,defaultdict,Counter
from bisect import bisect_left, bisect_right
from itertools import product,combinations,permutations

ipt = sys.stdin.readline

def iin():
    return int(ipt())
def lmin():
    return list(map(int,ipt().split()))

class dsu:

    def __init__(self,n):
        self.N = n
        self.cnt=[1]*self.N
        self.root=list(range(self.N))
        self.components = self.N

    def unite(self,x,y):
        x=self.leader(x)
        y=self.leader(y)
        if x!=y:
            self.components -= 1
            if self.cnt[x]<self.cnt[y]:
                x,y=y,x
            self.cnt[x]+=self.cnt[y]
            self.root[y]=x
            return x
        return None

    def leader(self,x):
        if self.root[x]==x:
            return x
        self.root[x]=self.leader(self.root[x])
        return self.root[x]

MOD = 998244353
#############################################################

H,W,N,D = lmin()
A = [[-1]*W for _ in range(H)]

L = [lmin() for _ in range(N)]
for i,(x,y) in enumerate(L):
    x,y = x-1,y-1
    A[x][y] = i

uf = dsu(N)

for idx,(x,y) in enumerate(L):
    x,y = x-1,y-1
    for i in range(x-D,x+D+1):
        for j in range(y-D,y+D+1):
            if abs(x-i)+abs(y-j) > D:
                continue
            if 0 <= i < H and 0 <= j < W:
                if A[i][j] != -1:
                    uf.unite(A[i][j],idx)

S = set()
T = set()

for i in range(N):
    l = uf.leader(i)
    if uf.cnt[l] == 1:
        T.add(l)
    else:
        S.add(l)

tmp = len(S)
#print(S,T)

ma = 0
mi = 1<<30

for x in range(H):
    for y in range(W):
        if A[x][y] != -1:
            continue
        
        ss = set()
        tt = set()
        for i in range(x-D,x+D+1):
            for j in range(y-D,y+D+1):
                if abs(x-i)+abs(y-j) > D:
                    continue
                if 0 <= i < H and 0 <= j < W:
                    if A[i][j] != -1:
                        l = uf.leader(A[i][j])
                        if l in S:
                            ss.add(l)
                        else:
                            tt.add(l)

        if not ss:
            if tt:
                ma = max(ma, tmp+1)
                mi = min(mi, tmp+1)
            else:
                ma = max(ma, tmp)
                mi = min(mi, tmp)
        else:
            ma = max(ma, tmp-len(ss)+1)
            mi = min(mi, tmp-len(ss)+1)


print(mi,ma)
0