結果

問題 No.7 プライムナンバーゲーム
ユーザー nakamura sosukenakamura sosuke
提出日時 2019-07-05 13:39:05
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 558 bytes
コンパイル時間 53 ms
コンパイル使用メモリ 11,912 KB
実行使用メモリ 16,460 KB
最終ジャッジ日時 2023-10-21 14:10:05
合計ジャッジ時間 4,635 ms
ジャッジサーバーID
(参考情報)
judge9 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 100 ms
16,240 KB
testcase_01 AC 99 ms
16,240 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 106 ms
16,244 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 204 ms
16,436 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 275 ms
16,456 KB
testcase_14 AC 323 ms
16,460 KB
testcase_15 AC 315 ms
16,460 KB
testcase_16 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

require 'prime'
N = gets.to_i

# 0=Lose, 1=Win
dp = Array.new(N+1){ nil }
dp[0], dp[1] = -1, -1 # whileの条件式で邪魔だから値入れとく
dp[2] = 0
dp[3] = 0

primes = Prime.each(N).to_a

result = 1
while dp.include? nil
  froms = []
  dp.each_with_index do | d, i |
    froms << i if d == (result ^ 1)
  end
  primes.each do | p |
    froms.each do | f |
      next if f+p > N
      dp[f+p] = result unless dp[f+p]
    end
  end
  result = result ^ 1 # bit反転
end

case dp[-1]
when 0
  puts 'Lose'
when 1
  puts 'Win'
else
  puts 'Illega'
end
0