結果

問題 No.7 プライムナンバーゲーム
ユーザー DialBirdDialBird
提出日時 2016-11-14 10:25:42
言語 Ruby
(3.3.0)
結果
AC  
実行時間 218 ms / 5,000 ms
コード長 320 bytes
コンパイル時間 233 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 12,928 KB
最終ジャッジ日時 2024-04-09 04:04:27
合計ジャッジ時間 3,243 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 109 ms
12,288 KB
testcase_01 AC 108 ms
12,544 KB
testcase_02 AC 103 ms
12,416 KB
testcase_03 AC 102 ms
12,288 KB
testcase_04 AC 103 ms
12,288 KB
testcase_05 AC 105 ms
12,672 KB
testcase_06 AC 103 ms
12,672 KB
testcase_07 AC 102 ms
12,544 KB
testcase_08 AC 104 ms
12,416 KB
testcase_09 AC 126 ms
12,544 KB
testcase_10 AC 107 ms
12,416 KB
testcase_11 AC 106 ms
12,288 KB
testcase_12 AC 218 ms
12,800 KB
testcase_13 AC 104 ms
12,672 KB
testcase_14 AC 134 ms
12,928 KB
testcase_15 AC 135 ms
12,800 KB
testcase_16 AC 205 ms
12,544 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:19: warning: assigned but unused variable - ans
Syntax OK

ソースコード

diff #

require 'prime'

MAX_N = 10000

@dp = [nil]*(MAX_N + 1)

def check(n)
  return @dp[n] if !@dp[n].nil?

  n.downto(2) do |i|
    next if !i.prime? || [0,1].include?(n-i)
    return @dp[n] = true if !check(n-i)
  end
  return @dp[n] = false
end

def main
  n = gets.to_i
  ans = check(n) ? "Win" : "Lose"
end

puts main() 
0