結果

問題 No.7 プライムナンバーゲーム
ユーザー cherrypi59cherrypi59
提出日時 2018-09-29 16:01:56
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 831 bytes
コンパイル時間 271 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-04-20 12:52:20
合計ジャッジ時間 3,962 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
11,008 KB
testcase_01 AC 33 ms
11,008 KB
testcase_02 AC 419 ms
11,008 KB
testcase_03 AC 55 ms
10,880 KB
testcase_04 AC 37 ms
11,008 KB
testcase_05 AC 42 ms
11,008 KB
testcase_06 AC 146 ms
11,008 KB
testcase_07 AC 105 ms
11,008 KB
testcase_08 AC 63 ms
11,136 KB
testcase_09 WA -
testcase_10 AC 29 ms
11,008 KB
testcase_11 AC 104 ms
10,880 KB
testcase_12 AC 301 ms
10,880 KB
testcase_13 AC 327 ms
11,008 KB
testcase_14 AC 404 ms
11,008 KB
testcase_15 WA -
testcase_16 AC 370 ms
10,880 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:
                win[i] = 0
                break
            if i - p <= 3 or win[i-p] == 0:
                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