結果

問題 No.168 ものさし
ユーザー Mao-betaMao-beta
提出日時 2024-03-22 11:45:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,042 ms / 2,000 ms
コード長 3,033 bytes
コンパイル時間 217 ms
コンパイル使用メモリ 81,828 KB
実行使用メモリ 86,340 KB
最終ジャッジ日時 2024-03-22 11:45:42
合計ジャッジ時間 10,550 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 337 ms
79,240 KB
testcase_01 AC 46 ms
57,828 KB
testcase_02 AC 46 ms
57,828 KB
testcase_03 AC 47 ms
57,828 KB
testcase_04 AC 47 ms
57,828 KB
testcase_05 AC 45 ms
57,828 KB
testcase_06 AC 64 ms
70,808 KB
testcase_07 AC 46 ms
57,828 KB
testcase_08 AC 46 ms
57,828 KB
testcase_09 AC 101 ms
77,068 KB
testcase_10 AC 140 ms
77,324 KB
testcase_11 AC 290 ms
79,000 KB
testcase_12 AC 669 ms
83,396 KB
testcase_13 AC 918 ms
85,700 KB
testcase_14 AC 903 ms
85,700 KB
testcase_15 AC 58 ms
68,228 KB
testcase_16 AC 102 ms
77,216 KB
testcase_17 AC 126 ms
77,472 KB
testcase_18 AC 162 ms
78,240 KB
testcase_19 AC 1,026 ms
86,340 KB
testcase_20 AC 1,033 ms
85,828 KB
testcase_21 AC 1,042 ms
86,212 KB
testcase_22 AC 1,037 ms
86,084 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import math
import bisect
from heapq import heapify, heappop, heappush
from collections import deque, defaultdict, Counter
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
MOD99 = 998244353

input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()
SMI = lambda: input().split()
SLI = lambda: list(SMI())
EI = lambda m: [NLI() for _ in range(m)]

from collections import defaultdict


class UnionFind:
    def __init__(self, n):
        # 親要素のノード番号を格納 xが根のとき-(サイズ)を格納
        self.par = [-1 for i in range(n)]
        self.n = n
        self.roots = set(range(n))
        self.group_num = n
        self.members = defaultdict(set)

        for i in range(n):
            self.members[i].add(i)

    def find(self, x):
        # 根ならその番号を返す
        if self.par[x] < 0:
            return x
        else:
            # 親の親は親
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def is_same(self, x, y):
        # 根が同じならTrue
        return self.find(x) == self.find(y)

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

        # 木のサイズを比較し、小さいほうから大きいほうへつなぐ
        if self.par[x] > self.par[y]:
            x, y = y, x

        self.group_num -= 1
        self.roots.discard(y)
        assert self.group_num == len(self.roots)

        self.members[x] |= self.members[y]
        self.members[y] = set()

        self.par[x] += self.par[y]
        self.par[y] = x

    def size(self, x):
        return -self.par[self.find(x)]

    def get_members(self, x):
        root = self.find(x)
        return self.members[root]

    def get_roots(self):
        return self.roots

    def group_count(self):
        return len(self.roots)

    def all_group_members(self):
        return self.members

    def __repr__(self):
        return '\n'.join('{}: {}'.format(r, self.members[r]) for r in self.roots)


def main():
    N = NI()
    XY = EI(N)
    D = [[0]*N for _ in range(N)]
    for i in range(N):
        for j in range(N):
            xi, yi = XY[i]
            xj, yj = XY[j]
            d2 = (xi-xj)**2 + (yi-yj)**2
            if d2 == 0:
                D[i][j] = 0
            else:
                d = math.isqrt(d2-1) + 1
                D[i][j] = (d+9) // 10

    def judge(X):
        uf = UnionFind(N)
        for i in range(N):
            for j in range(i+1, N):
                if D[i][j] <= X:
                    uf.unite(i, j)
        return uf.is_same(0, N-1)

    ok = 10**20
    ng = 0
    while abs(ok - ng) > 1:
        X = (ok + ng) // 2
        if judge(X):
            ok = X
        else:
            ng = X

    print(ok * 10)


if __name__ == "__main__":
    main()
0