結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,372 KB
testcase_01 AC 17 ms
8,336 KB
testcase_02 AC 16 ms
8,364 KB
testcase_03 AC 17 ms
8,480 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,516 KB
testcase_21 AC 17 ms
8,396 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)
    maxx = maxy = -2000
    minx = miny = 2000
    maxxp = maxyp = minxp = minyp = None

    for i in g:
        p = ps[i]
        if p[0] > maxx:
            maxx = p[0]
            maxxp = p
        if p[0] < minx:
            minx = p[0]
            minxp = p
        if p[1] > maxy:
            maxy = p[1]
            maxyp = p
        if p[1] < miny:
            miny = p[1]
            minyp = p

    ms = list({maxxp, minxp, maxyp, minyp})
    if len(ms) < 2:
        return 0
    return max(dist2(ms[i], ms[j]) for i in range(len(ms)) for j in range(i + 1, len(ms)))


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