結果
問題 |
No.7 プライムナンバーゲーム
|
ユーザー |
![]() |
提出日時 | 2015-08-15 07:50:42 |
言語 | PyPy2 (7.3.15) |
結果 |
AC
|
実行時間 | 720 ms / 5,000 ms |
コード長 | 678 bytes |
コンパイル時間 | 281 ms |
コンパイル使用メモリ | 77,188 KB |
実行使用メモリ | 84,976 KB |
最終ジャッジ日時 | 2024-10-01 15:35:54 |
合計ジャッジ時間 | 5,594 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 17 |
ソースコード
import sys import time sys.setrecursionlimit(1 << 30) N = input() dp = [-1 for i in range(10010)] prime = [True for i in range(10010)] def sieve(): prime[0] = False prime[1] = False for i in range(2, 10010): if (prime[i]): for j in range(i * i, 10010, i): prime[j] = False def memo(pos): if (pos == 0 or pos == 1): return True win = False if (dp[pos] >= 0): return dp[pos] for i in range(2, pos): if (prime[i]): win |= not memo(pos - i) if (win): break dp[pos] = win return win sieve() if (memo(N)): print "Win" else: print "Lose"