結果

問題 No.94 圏外です。(EASY)
ユーザー しらっ亭しらっ亭
提出日時 2015-06-11 17:41:29
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 298 ms / 5,000 ms
コード長 1,464 bytes
コンパイル時間 352 ms
コンパイル使用メモリ 11,068 KB
実行使用メモリ 32,132 KB
最終ジャッジ日時 2023-09-08 14:30:00
合計ジャッジ時間 5,016 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,440 KB
testcase_01 AC 17 ms
8,344 KB
testcase_02 AC 17 ms
8,520 KB
testcase_03 AC 17 ms
8,408 KB
testcase_04 AC 20 ms
8,656 KB
testcase_05 AC 27 ms
9,352 KB
testcase_06 AC 45 ms
11,184 KB
testcase_07 AC 84 ms
14,592 KB
testcase_08 AC 154 ms
21,064 KB
testcase_09 AC 287 ms
32,052 KB
testcase_10 AC 286 ms
32,132 KB
testcase_11 AC 285 ms
32,052 KB
testcase_12 AC 287 ms
32,104 KB
testcase_13 AC 287 ms
32,072 KB
testcase_14 AC 288 ms
32,008 KB
testcase_15 AC 286 ms
31,980 KB
testcase_16 AC 282 ms
32,072 KB
testcase_17 AC 290 ms
32,112 KB
testcase_18 AC 285 ms
32,040 KB
testcase_19 AC 298 ms
32,016 KB
testcase_20 AC 17 ms
8,388 KB
testcase_21 AC 17 ms
8,296 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math


def dist2(p1, p2):
    return (p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2

def md(ds, g):
    g = list(g)

    m = 0
    for i in range(len(g)):
        for j in range(i + 1, len(g)):
            d2 = ds[g[i]][g[j]]
            if d2 > m:
                m = d2
    return m


def solve(n, ps):
    ds = [[0] * n for i in range(n)]

    for i in range(n):
        pi = ps[i]
        for j in range(i + 1, n):
            pj = ps[j]
            d2 = dist2(pi, pj)
            ds[i][j] = ds[j][i] = d2

    g = [None] * n
    gs = []

    # 相互通信できるグループに分ける
    for i in range(n):
        if g[i] is not None:
            continue
        g[i] = {i}
        gs.append(g[i])
        stack = [i]
        while stack:
            j = stack.pop()
            for k in range(n):
                if g[k] is not None:
                    continue
                if ds[j][k] > 100:
                    continue
                g[k] = g[j]
                g[k].add(k)
                stack.append(k)

    # グループ内のアンテナの間の最大距離をグループごとに求める
    # それの最大値 + 2 が答え
    if len(gs) < 1:
        return 1
    mmd = math.sqrt(max(md(ds, g) for g in gs))
    return mmd + 2


def main():
    n = int(input())
    ps = []
    for i in range(n):
        ps.append(tuple(map(int, input().split())))

    a = solve(n, ps)
    print(a)


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