結果

問題 No.199 星を描こう
ユーザー matsu7874matsu7874
提出日時 2018-12-17 01:32:48
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 1,223 bytes
コンパイル時間 98 ms
コンパイル使用メモリ 11,852 KB
実行使用メモリ 10,148 KB
最終ジャッジ日時 2023-10-25 23:21:32
合計ジャッジ時間 1,941 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
10,148 KB
testcase_01 AC 28 ms
10,148 KB
testcase_02 AC 27 ms
10,148 KB
testcase_03 AC 28 ms
10,148 KB
testcase_04 AC 27 ms
10,148 KB
testcase_05 AC 28 ms
10,148 KB
testcase_06 AC 28 ms
10,148 KB
testcase_07 AC 28 ms
10,148 KB
testcase_08 AC 27 ms
10,148 KB
testcase_09 AC 27 ms
10,148 KB
testcase_10 AC 28 ms
10,148 KB
testcase_11 AC 30 ms
10,148 KB
testcase_12 AC 27 ms
10,148 KB
testcase_13 AC 28 ms
10,148 KB
testcase_14 AC 28 ms
10,148 KB
testcase_15 AC 29 ms
10,148 KB
testcase_16 AC 28 ms
10,148 KB
testcase_17 AC 27 ms
10,148 KB
testcase_18 AC 28 ms
10,148 KB
testcase_19 AC 28 ms
10,148 KB
testcase_20 AC 29 ms
10,148 KB
testcase_21 AC 28 ms
10,148 KB
testcase_22 AC 28 ms
10,148 KB
testcase_23 AC 28 ms
10,148 KB
testcase_24 AC 28 ms
10,148 KB
testcase_25 AC 29 ms
10,148 KB
testcase_26 AC 28 ms
10,148 KB
testcase_27 AC 28 ms
10,148 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def det(p, q):
    return p[0] * q[1] - p[1] * q[0]


def sub(p, q):
    return (p[0] - q[0], p[1] - q[1])


def get_convex_hull(points):
    # どの3点も直線上に並んでいないと仮定する。
    n = len(points)
    points.sort()
    size_convex_hull = 0
    ch = []
    for i in range(n):
        while size_convex_hull > 1:
            v_cur = sub(ch[-1], ch[-2])
            v_new = sub(points[i], ch[-2])
            if det(v_cur, v_new) > 0:
                break
            size_convex_hull -= 1
            ch.pop()
        ch.append(points[i])
        size_convex_hull += 1

    t = size_convex_hull
    for i in range(n - 2, -1, -1):
        while size_convex_hull > t:
            v_cur = sub(ch[-1], ch[-2])
            v_new = sub(points[i], ch[-2])
            if det(v_cur, v_new) > 0:
                break
            size_convex_hull -= 1
            ch.pop()
        ch.append(points[i])
        size_convex_hull += 1

    return ch[:-1]


def main():
    n = 5
    points = [list(map(int, input().split())) for i in range(n)]
    convex_hull = get_convex_hull(points)
    if len(convex_hull) == 5:
        print('YES')
    else:
        print('NO')


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