結果
問題 | No.7 プライムナンバーゲーム |
ユーザー |
![]() |
提出日時 | 2017-01-05 04:31:36 |
言語 | Nim (2.2.0) |
結果 |
AC
|
実行時間 | 11 ms / 5,000 ms |
コード長 | 522 bytes |
コンパイル時間 | 3,640 ms |
コンパイル使用メモリ | 65,664 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-01 15:54:04 |
合計ジャッジ時間 | 3,379 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 17 |
コンパイルメッセージ
/home/judge/data/code/Main.nim(1, 28) Warning: imported and not used: 'algorithm' [UnusedImport]
ソースコード
import strutils, sequtils, algorithm let N = stdin.readline.parseInt var sieve = newSeq[bool](N+1) primes = newSeq[int]() for i in 2..N: if not sieve[i]: primes.add(i) for j in countup(2 * i, N, i): sieve[j] = true var dp = newSeqWith(N+1, -1) proc dfs(n: int): int = if n <= 1: return 1 elif dp[n] != -1: return dp[n] result = 0 for p in primes: if p > n: break if dfs(n-p) == 0: result = 1 break dp[n] = result echo(if dfs(N) == 1: "Win" else: "Lose")