結果

問題 No.7 プライムナンバーゲーム
ユーザー matsu7874matsu7874
提出日時 2015-08-16 13:51:35
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 735 ms / 5,000 ms
コード長 895 bytes
コンパイル時間 91 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 11,904 KB
最終ジャッジ日時 2024-04-09 03:50:13
合計ジャッジ時間 5,717 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
10,752 KB
testcase_01 AC 29 ms
10,752 KB
testcase_02 AC 735 ms
11,904 KB
testcase_03 AC 67 ms
11,136 KB
testcase_04 AC 37 ms
10,880 KB
testcase_05 AC 38 ms
11,008 KB
testcase_06 AC 208 ms
11,264 KB
testcase_07 AC 142 ms
11,264 KB
testcase_08 AC 79 ms
11,008 KB
testcase_09 AC 331 ms
11,392 KB
testcase_10 AC 29 ms
10,880 KB
testcase_11 AC 148 ms
11,136 KB
testcase_12 AC 456 ms
11,520 KB
testcase_13 AC 553 ms
11,648 KB
testcase_14 AC 703 ms
11,776 KB
testcase_15 AC 687 ms
11,648 KB
testcase_16 AC 627 ms
11,776 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10000)
def prime_sieve(n):
    is_prime = [True for i in range(n+1)]
    is_prime[0] = False
    is_prime[1] = False
    for i in range(4, n+1, 2):
        is_prime[i] = False
    for i in range(3, int(n**0.5+1), 2):
        if is_prime[i]:
            for j in range(i*i, n+1, i):
                is_prime[j] = False
    return [i for i in range(n+1) if is_prime[i]]

N = int(input())
P = prime_sieve(N)
lP = len(P)
win = 1
lose = 0
undefined = -1
F = [undefined for i in range(N+1)]
F[0] = win
F[1] = win

def dfs(n):
    if F[n] == win:
        return win
    elif F[n] == lose:
        return lose
    else:
        flg = lose
        i = 0
        while i<lP and n-P[i] >= 0:
            if dfs(n-P[i]) == lose:
                F[n] = win
                return win
            i += 1
        F[n] = lose
        return lose

print(['Lose', 'Win'][dfs(N)])
0