結果

問題 No.2696 Sign Creation
ユーザー rlangevinrlangevin
提出日時 2024-03-22 22:16:25
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 2,527 bytes
コンパイル時間 215 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 84,660 KB
最終ジャッジ日時 2024-03-22 22:16:45
合計ジャッジ時間 19,843 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
62,104 KB
testcase_01 AC 54 ms
64,444 KB
testcase_02 AC 40 ms
53,460 KB
testcase_03 AC 48 ms
61,572 KB
testcase_04 AC 45 ms
59,720 KB
testcase_05 AC 47 ms
61,572 KB
testcase_06 AC 41 ms
53,460 KB
testcase_07 AC 41 ms
53,460 KB
testcase_08 AC 224 ms
78,724 KB
testcase_09 AC 115 ms
76,716 KB
testcase_10 AC 232 ms
78,180 KB
testcase_11 AC 121 ms
75,964 KB
testcase_12 AC 124 ms
75,964 KB
testcase_13 AC 1,446 ms
83,196 KB
testcase_14 AC 844 ms
84,348 KB
testcase_15 AC 795 ms
84,612 KB
testcase_16 AC 1,353 ms
83,076 KB
testcase_17 AC 546 ms
76,960 KB
testcase_18 AC 428 ms
78,468 KB
testcase_19 AC 767 ms
81,336 KB
testcase_20 AC 166 ms
76,572 KB
testcase_21 AC 560 ms
84,660 KB
testcase_22 AC 753 ms
78,944 KB
testcase_23 AC 787 ms
84,276 KB
testcase_24 AC 801 ms
84,152 KB
testcase_25 AC 852 ms
80,948 KB
testcase_26 AC 614 ms
78,408 KB
testcase_27 AC 635 ms
77,548 KB
testcase_28 AC 507 ms
78,184 KB
testcase_29 AC 646 ms
76,992 KB
testcase_30 AC 583 ms
77,264 KB
testcase_31 TLE -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

class UnionFind():
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]

    def is_same(self, x, y):
        return self.find(x) == self.find(y)

    def get_size(self, x):
        x = self.find(x)
        return self.size[x]


H, W, N, D = map(int, input().split())
X, Y = [0] * N, [0] * N
U = UnionFind(N)
DD = dict()
for i in range(N):
    X[i], Y[i] = map(int, input().split())
    X[i], Y[i] = X[i] - 1, Y[i] - 1
    DD[(X[i], Y[i])] = i
    
for i in range(N):
    for a in range(X[i] - D, X[i] + D + 1):
        for b in range(Y[i] - D, Y[i] + D + 1):
            if abs(a - X[i]) + abs(b - Y[i]) > D:
                continue
            if a < 0 or a > H - 1 or b < 0 or b > W - 1:
                continue
            if (a, b) not in DD:
                continue
            ind = DD[(a, b)]
            U.union(i, ind)
         
   
mi, ma = 0, -10 ** 18
for i in range(H):
    for j in range(W):
        if (i, j) in DD:
            continue
        S = set()
        v = 0
        flag = 0
        for a in range(i - D, i + D + 1):
            for b in range(j - D, j + D + 1):
                if abs(a - i) + abs(b - j) > D:
                    continue
                if a < 0 or a > H - 1 or b < 0 or b > W - 1:
                    continue
                if (a, b) not in DD:
                    continue
                ind = U.find(DD[(a, b)])
                if ind in S:
                    continue
                S.add(ind)
                if U.get_size(ind) >= 2:
                    v -= 1
                else:
                    flag = 1
                    
        if v < 0:
            v += 1
                         
        mi = min(mi, v + flag)
        ma = max(ma, v + flag)
        
ans = 0
S = set()
for i in range(N):
    if U.find(i) in S:
        continue
    S.add(U.find(i))
    if U.get_size(i) >= 2:
        ans += 1
        
print(ans + mi, ans + ma)
0