結果

問題 No.7 プライムナンバーゲーム
ユーザー shinjiwebshinjiweb
提出日時 2016-08-28 02:33:04
言語 Ruby
(3.3.0)
結果
AC  
実行時間 1,223 ms / 5,000 ms
コード長 284 bytes
コンパイル時間 58 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 56,960 KB
最終ジャッジ日時 2024-04-09 04:03:04
合計ジャッジ時間 10,142 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 109 ms
12,672 KB
testcase_01 AC 104 ms
12,416 KB
testcase_02 AC 1,218 ms
56,832 KB
testcase_03 AC 172 ms
18,304 KB
testcase_04 AC 121 ms
13,568 KB
testcase_05 AC 123 ms
13,568 KB
testcase_06 AC 432 ms
33,024 KB
testcase_07 AC 331 ms
29,696 KB
testcase_08 AC 203 ms
20,352 KB
testcase_09 AC 602 ms
36,864 KB
testcase_10 AC 104 ms
12,416 KB
testcase_11 AC 337 ms
30,080 KB
testcase_12 AC 908 ms
44,928 KB
testcase_13 AC 965 ms
48,512 KB
testcase_14 AC 1,223 ms
56,960 KB
testcase_15 AC 1,161 ms
55,552 KB
testcase_16 AC 1,076 ms
54,144 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

require 'prime'
n = gets.to_i
dp = Array.new(10001, false)
primes = Prime.each(n).to_a
2.upto(n) do |i|
  sub_p = primes.select { |p| p <= i }
  sub_p.each do |p|
    next if i-p <= 1
    if dp[i-p] == false
      dp[i] = true
      break
    end
  end
end
puts dp[n] ? 'Win' : 'Lose'
0