結果

問題 No.7 プライムナンバーゲーム
ユーザー DialBirdDialBird
提出日時 2016-11-13 19:50:28
言語 Ruby
(3.3.0)
結果
AC  
実行時間 1,188 ms / 5,000 ms
コード長 435 bytes
コンパイル時間 293 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 56,832 KB
最終ジャッジ日時 2024-04-09 04:04:45
合計ジャッジ時間 9,938 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 102 ms
12,416 KB
testcase_01 AC 99 ms
12,544 KB
testcase_02 AC 1,188 ms
56,832 KB
testcase_03 AC 168 ms
18,176 KB
testcase_04 AC 120 ms
13,696 KB
testcase_05 AC 117 ms
13,824 KB
testcase_06 AC 414 ms
33,664 KB
testcase_07 AC 311 ms
29,184 KB
testcase_08 AC 193 ms
20,480 KB
testcase_09 AC 578 ms
36,864 KB
testcase_10 AC 100 ms
12,288 KB
testcase_11 AC 314 ms
29,312 KB
testcase_12 AC 858 ms
43,648 KB
testcase_13 AC 919 ms
48,896 KB
testcase_14 AC 1,150 ms
56,704 KB
testcase_15 AC 1,096 ms
55,552 KB
testcase_16 AC 1,031 ms
54,272 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:28: warning: assigned but unused variable - ans
Syntax OK

ソースコード

diff #

require 'prime'

MAX_N = 10000

def prime_nums(n)
  arr = []
  Prime.each(n) { |p| arr << p }
  arr
end

def main
  n = gets.to_i
  dp = [false]*(MAX_N + 1)
  prime_arr = prime_nums(n)

  2.upto(n) do |i|
    res = true
    use_primes = prime_arr.select{ |p| p < i }
    use_primes.each do |p|
      if dp[i - p]
        res = false
        break
      end
    end
    dp[i] = res
  end

  ans = dp[n] ? 'Lose' : 'Win'
end

puts main()
0