結果

問題 No.7 プライムナンバーゲーム
ユーザー rpy3cpprpy3cpp
提出日時 2015-08-06 20:22:51
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
WA  
実行時間 -
コード長 1,026 bytes
コンパイル時間 132 ms
コンパイル使用メモリ 10,944 KB
実行使用メモリ 8,768 KB
最終ジャッジ日時 2023-09-25 04:15:23
合計ジャッジ時間 2,435 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

def primes2(limit):
    ''' returns a list of prime numbers upto limit.
    source: Rossetta code: Sieve of Eratosthenes
    http://rosettacode.org/wiki/Sieve_of_Eratosthenes#Odds-only_version_of_the_array_sieve_above
    '''
    if limit < 2: return []
    if limit < 3: return [2]
    lmtbf = (limit - 3) // 2
    buf = [True] * (lmtbf + 1)
    for i in range((int(limit ** 0.5) - 3) // 2 + 1):
        if buf[i]:
            p = i + i + 3
            s = p * (i + 1) + i
            buf[s::p] = [False] * ((lmtbf - s) // p + 1)
    return [2] + [i + i + 3 for i, v in enumerate(buf) if v]

def solve(N):
    primes = primes2(N)
    dp = [-1] * (N + 1)
    dp[0] = 1
    dp[1] = 1
    for n in range(2, N + 1):
        for p in primes:
            if p > n:
                dp[n] = 0
                break
            if dp[n - p] == 0:
                dp[n] = 1
                break
        else:
            dp[n] = 0
    print(dp)
    return dp[N]

N = int(input())
if solve(N):
    print('Win')
else:
    print('Lose')
0