結果

問題 No.7 プライムナンバーゲーム
ユーザー finefine
提出日時 2016-03-23 00:52:51
言語 Ruby
(3.3.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 780 bytes
コンパイル時間 284 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 26,368 KB
最終ジャッジ日時 2024-04-17 22:51:10
合計ジャッジ時間 3,461 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 89 ms
12,288 KB
testcase_01 AC 89 ms
12,288 KB
testcase_02 AC 94 ms
12,416 KB
testcase_03 AC 92 ms
12,416 KB
testcase_04 AC 96 ms
12,288 KB
testcase_05 AC 95 ms
12,544 KB
testcase_06 AC 91 ms
12,416 KB
testcase_07 AC 104 ms
12,416 KB
testcase_08 AC 86 ms
12,416 KB
testcase_09 AC 177 ms
18,944 KB
testcase_10 AC 82 ms
12,416 KB
testcase_11 AC 85 ms
12,416 KB
testcase_12 WA -
testcase_13 AC 91 ms
12,544 KB
testcase_14 AC 279 ms
26,368 KB
testcase_15 AC 265 ms
26,240 KB
testcase_16 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

require 'prime'

def hoge a,b
    if a
        return b
    else
        return !b
    end
end
def sol n,f,memo
    if memo[n - 2] != nil
        return hoge(f,memo[n - 2])
    end
    if n < 2 
        memo[n - 2] = hoge(f,f)
        return f
    elsif n < 4
        memo[n - 2] = hoge(f,!f)
        return !f
    end
    Prime.each(n).to_a.reverse.each{|x|
        if f
            if sol(n - x,false,memo)
                memo[n - 2] = true
                return true
            end
        else
            if !sol(n - x,true,memo)
                memo[n - 2] = true
                return false
            end
        end
        }
    memo[n - 2] = false
    return !f
end

n = gets.to_i
memo = Array.new(n - 2)
if sol(n,true,memo)
    puts 'Win'
else
    puts 'Lose'
end
0