結果

問題 No.94 圏外です。(EASY)
ユーザー しらっ亭しらっ亭
提出日時 2015-06-11 16:43:31
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,208 bytes
コンパイル時間 73 ms
コンパイル使用メモリ 11,020 KB
実行使用メモリ 8,820 KB
最終ジャッジ日時 2023-09-20 20:50:52
合計ジャッジ時間 3,059 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,364 KB
testcase_01 AC 16 ms
8,492 KB
testcase_02 AC 16 ms
8,340 KB
testcase_03 AC 15 ms
8,348 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 16 ms
8,380 KB
testcase_21 AC 16 ms
8,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math


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

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

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


def solve(n, ps):
    g = [None] * n
    gs = []

    # 相互通信できるグループに分ける。 O(n^2)
    for i in range(n):
        pi = ps[i]
        if g[i] is None:
            g[i] = {i}
            gs.append(g[i])
        for j in range(i + 1, n):
            if g[j] is not None:
                continue
            pj = ps[j]
            if dist2(pi, pj) <= 100:
                g[i].add(j)
                g[j] = g[i]

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