結果

問題 No.7 プライムナンバーゲーム
ユーザー cherrypi59cherrypi59
提出日時 2018-09-29 16:09:14
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 445 ms / 5,000 ms
コード長 839 bytes
コンパイル時間 131 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-04-09 04:32:03
合計ジャッジ時間 4,212 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
11,008 KB
testcase_01 AC 30 ms
11,008 KB
testcase_02 AC 441 ms
11,008 KB
testcase_03 AC 56 ms
11,008 KB
testcase_04 AC 37 ms
11,008 KB
testcase_05 AC 39 ms
11,008 KB
testcase_06 AC 148 ms
11,008 KB
testcase_07 AC 110 ms
11,136 KB
testcase_08 AC 66 ms
11,008 KB
testcase_09 AC 210 ms
11,136 KB
testcase_10 AC 32 ms
11,136 KB
testcase_11 AC 111 ms
11,008 KB
testcase_12 AC 327 ms
11,008 KB
testcase_13 AC 345 ms
11,008 KB
testcase_14 AC 445 ms
11,008 KB
testcase_15 AC 419 ms
11,136 KB
testcase_16 AC 395 ms
11,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

MAX_N = 10 ** 4
prime, is_prime = [0] * (MAX_N+1), [1] * (MAX_N+1)
win = [-1] * (MAX_N+1)


def eratosthenes(n):
    cnt = 0
    is_prime[0] = is_prime[1] = 0

    for i in range(2, n+1):
        if is_prime[i]:
            prime[cnt] = i
            cnt += 1

            for j in range(i, n+1, i):
                is_prime[j] = 0

    return cnt


def solve(x):
    for i in range(4, x+1):
        for p in prime:
            if i - p < 2 or not p:
                win[i] = 0
                break
            if i - p <= 3 or not win[i-p]:
                win[i] = 1
                break
        else:
            win[x] = 0

    return win[x]


def main():
    n = int(input())

    eratosthenes(n)

    win[2] = win[3] = 0
    if solve(n):
        print("Win")
    else:
        print("Lose")


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