結果

問題 No.7 プライムナンバーゲーム
ユーザー keibkeib
提出日時 2019-03-06 19:47:58
言語 Swift
(5.10.0)
結果
AC  
実行時間 17 ms / 5,000 ms
コード長 544 bytes
コンパイル時間 13,249 ms
コンパイル使用メモリ 179,908 KB
実行使用メモリ 16,128 KB
最終ジャッジ日時 2024-04-09 04:35:10
合計ジャッジ時間 14,348 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
15,872 KB
testcase_01 AC 12 ms
15,616 KB
testcase_02 AC 16 ms
16,000 KB
testcase_03 AC 13 ms
16,000 KB
testcase_04 AC 12 ms
15,488 KB
testcase_05 AC 12 ms
15,616 KB
testcase_06 AC 13 ms
15,488 KB
testcase_07 AC 13 ms
16,000 KB
testcase_08 AC 13 ms
16,000 KB
testcase_09 AC 15 ms
15,488 KB
testcase_10 AC 12 ms
15,744 KB
testcase_11 AC 14 ms
16,000 KB
testcase_12 AC 15 ms
15,616 KB
testcase_13 AC 15 ms
15,872 KB
testcase_14 AC 16 ms
16,128 KB
testcase_15 AC 17 ms
15,616 KB
testcase_16 AC 15 ms
15,744 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import Foundation


let n = Int(readLine()!)!

let primes =  { () -> [Int] in
  var multiples = Set<Int>()
  return (2 ..< n).filter { i in
    let ret = !multiples.contains(i)
    var m = 2
    while i * m < n {
      multiples.insert(i * m)
      m += 1
    }
    return ret
  }
}()

var dp: [Bool] = [true, true]
for i in 2 ... n {
  var found = false
  for p in primes {
    if p > i {
      break
    }
    if !dp[i - p] {
      found = true
      break
    }
  }
  dp.append(found)
} 
if dp[n] {
  print("Win")
} else {
  print("Lose")
}
0