結果

問題 No.2696 Sign Creation
ユーザー mymelochanmymelochan
提出日時 2024-03-22 22:13:29
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 814 ms / 2,500 ms
コード長 2,569 bytes
コンパイル時間 217 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 92,616 KB
最終ジャッジ日時 2024-03-27 17:58:17
合計ジャッジ時間 11,250 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
64,040 KB
testcase_01 AC 55 ms
64,168 KB
testcase_02 AC 45 ms
55,596 KB
testcase_03 AC 53 ms
63,640 KB
testcase_04 AC 50 ms
61,788 KB
testcase_05 AC 52 ms
63,640 KB
testcase_06 AC 46 ms
55,596 KB
testcase_07 AC 45 ms
55,596 KB
testcase_08 AC 200 ms
78,788 KB
testcase_09 AC 92 ms
75,940 KB
testcase_10 AC 205 ms
78,628 KB
testcase_11 AC 115 ms
76,204 KB
testcase_12 AC 116 ms
76,204 KB
testcase_13 AC 639 ms
83,764 KB
testcase_14 AC 560 ms
84,660 KB
testcase_15 AC 502 ms
83,892 KB
testcase_16 AC 585 ms
83,636 KB
testcase_17 AC 297 ms
77,724 KB
testcase_18 AC 305 ms
79,368 KB
testcase_19 AC 466 ms
82,016 KB
testcase_20 AC 143 ms
77,492 KB
testcase_21 AC 407 ms
85,148 KB
testcase_22 AC 400 ms
79,400 KB
testcase_23 AC 529 ms
83,852 KB
testcase_24 AC 518 ms
84,112 KB
testcase_25 AC 519 ms
81,996 KB
testcase_26 AC 329 ms
78,508 KB
testcase_27 AC 354 ms
79,272 KB
testcase_28 AC 324 ms
79,496 KB
testcase_29 AC 329 ms
77,992 KB
testcase_30 AC 318 ms
77,996 KB
testcase_31 AC 814 ms
92,616 KB
testcase_32 AC 57 ms
66,248 KB
testcase_33 AC 91 ms
76,336 KB
testcase_34 AC 60 ms
68,308 KB
testcase_35 AC 44 ms
55,596 KB
testcase_36 AC 44 ms
55,596 KB
testcase_37 AC 44 ms
55,596 KB
testcase_38 AC 43 ms
55,596 KB
testcase_39 AC 44 ms
55,596 KB
testcase_40 AC 43 ms
55,596 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