結果

問題 No.2696 Sign Creation
ユーザー ntudantuda
提出日時 2024-03-23 15:51:43
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,528 bytes
コンパイル時間 224 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 114,464 KB
最終ジャッジ日時 2024-03-23 15:52:01
合計ジャッジ時間 17,054 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
66,008 KB
testcase_01 AC 38 ms
59,204 KB
testcase_02 AC 35 ms
53,460 KB
testcase_03 AC 40 ms
59,588 KB
testcase_04 AC 41 ms
59,588 KB
testcase_05 AC 41 ms
59,588 KB
testcase_06 AC 36 ms
53,460 KB
testcase_07 AC 35 ms
53,460 KB
testcase_08 AC 192 ms
77,468 KB
testcase_09 AC 62 ms
72,432 KB
testcase_10 AC 174 ms
78,116 KB
testcase_11 AC 78 ms
75,764 KB
testcase_12 AC 80 ms
75,764 KB
testcase_13 AC 1,573 ms
87,916 KB
testcase_14 AC 691 ms
88,300 KB
testcase_15 AC 660 ms
88,044 KB
testcase_16 AC 1,567 ms
88,172 KB
testcase_17 AC 423 ms
76,548 KB
testcase_18 AC 334 ms
78,800 KB
testcase_19 AC 711 ms
83,820 KB
testcase_20 AC 101 ms
75,788 KB
testcase_21 AC 598 ms
93,780 KB
testcase_22 AC 488 ms
78,292 KB
testcase_23 AC 605 ms
86,468 KB
testcase_24 AC 638 ms
86,596 KB
testcase_25 AC 798 ms
82,688 KB
testcase_26 AC 402 ms
76,620 KB
testcase_27 AC 420 ms
77,604 KB
testcase_28 AC 348 ms
77,824 KB
testcase_29 AC 387 ms
76,064 KB
testcase_30 AC 376 ms
76,308 KB
testcase_31 TLE -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

def root(x):
    if P[x] < 0: return x
    P[x] = root(P[x])  # 経路圧縮
    return P[x]
def unite(x,y):
    x = root(x)
    y = root(y)
    if x == y: return
    if x > y: x,y = y,x
    P[x] += P[y]
    P[y] = x

def same(x,y):
    return root(x) == root(y)

def size(x):
    x = root(x)
    return -P[x]


H, W, N, D = map(int, input().split())
XY = [list(map(int,input().split())) for _ in range(N)]
P = [-1] * N
dic = {}
for i in range(N):
    dic[tuple(XY[i])] = i

def search(x, y):
    ret = set()
    for i in range(-D, D+1):
        if 0 < x + i <= H:
            xi = x + i
            for j in range(-D + abs(i), D - abs(i) + 1):
                if 0 < y + j <= W:
                    yj = y+j
                    if (xi,yj) in dic:
                        ret.add(dic[(xi,yj)])
    return ret

for i in range(N):
    x,y = XY[i]
    for j in search(x,y):
        unite(i,j)

Q = set()
for i in range(N):
    if size(i) >= 2:
        Q.add(root(i))
gcount = len(Q)


ansmax = 0
ansmin = gcount
for i in range(1,H+1):
    for j in range(1,W+1):
        tmp = search(i,j)
        Q1 = set()
        Q2 = set()
        for k in tmp:
            if size(k) > 1:
                Q2.add(root(k))
            else:
                Q1.add(k)
        if Q2:
            tmp2 = gcount - len(Q2) + 1
            ansmax = max(ansmax, tmp2)
            ansmin = min(ansmin, tmp2)
        elif Q1:
            tmp2 = gcount + 1
            ansmax = max(ansmax,tmp2)
            ansmin = min(ansmin,tmp2)

print(ansmin,ansmax)

0