結果

問題 No.7 プライムナンバーゲーム
ユーザー zombietanzombietan
提出日時 2016-05-08 02:07:54
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,806 ms / 5,000 ms
コード長 581 bytes
コンパイル時間 160 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-04-09 04:00:22
合計ジャッジ時間 13,179 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
10,880 KB
testcase_01 AC 32 ms
10,752 KB
testcase_02 AC 1,806 ms
10,880 KB
testcase_03 AC 144 ms
10,752 KB
testcase_04 AC 60 ms
10,752 KB
testcase_05 AC 60 ms
10,752 KB
testcase_06 AC 579 ms
10,752 KB
testcase_07 AC 369 ms
10,752 KB
testcase_08 AC 183 ms
10,880 KB
testcase_09 AC 812 ms
10,880 KB
testcase_10 AC 29 ms
10,880 KB
testcase_11 AC 372 ms
10,880 KB
testcase_12 AC 1,266 ms
10,880 KB
testcase_13 AC 1,320 ms
10,880 KB
testcase_14 AC 1,740 ms
10,880 KB
testcase_15 AC 1,635 ms
11,008 KB
testcase_16 AC 1,518 ms
10,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
def primes():
    n = 2
    p = []
    while True:
        if not any( n % f == 0 for f in p ):
            yield(n)
            p.append( n )
        n += 1

p = primes()
r = []
while True:
    d = next(p)
    if d <= N:
        r.append(d)
    else:
        break

memo = ['']*(N+1)
memo[0] = 'Win'
memo[1] = 'Win'

for i in range(2, N+1):
    c = []
    for s in r:
        if s <= i:
            h = memo[i-s]
            c.append(h)
        else:
            break
    if 'Lose' in c:
        memo[i] = 'Win'
    else:
        memo[i] = 'Lose'

print(memo[N])
0