結果

問題 No.7 プライムナンバーゲーム
ユーザー 🍡yurahuna🍡yurahuna
提出日時 2016-04-28 20:50:19
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 590 bytes
コンパイル時間 224 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 80,760 KB
最終ジャッジ日時 2024-04-15 05:11:54
合計ジャッジ時間 2,422 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,020 KB
testcase_01 AC 37 ms
52,356 KB
testcase_02 RE -
testcase_03 AC 63 ms
70,144 KB
testcase_04 AC 53 ms
64,512 KB
testcase_05 AC 53 ms
64,000 KB
testcase_06 RE -
testcase_07 RE -
testcase_08 AC 64 ms
69,376 KB
testcase_09 RE -
testcase_10 AC 37 ms
52,828 KB
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

prime = []
def setPrime(n):
    n += 1
    alive = [True] * n
    i = 2
    while i < n:
        if alive[i]:
            prime.append(i)
            j = 2 * i
            while j < n:
                alive[j] = False
                j += i
        i += 1


def dfs(n):
    if memo[n] != None:
        return memo[n]

    ret = False
    for p in prime:
        if n - p < 0:
            break
        ret |= not dfs(n - p)

    memo[n] = ret
    return ret


N = int(input())
setPrime(N)
memo = [None] * (N + 1)
memo[0] = memo[1] = True
if dfs(N):
    print("Win")
else:
    print("Lose")
0