結果

問題 No.7 プライムナンバーゲーム
ユーザー maimai
提出日時 2017-02-04 10:59:42
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 529 bytes
コンパイル時間 678 ms
コンパイル使用メモリ 11,536 KB
実行使用メモリ 15,676 KB
最終ジャッジ日時 2023-08-25 20:06:09
合計ジャッジ時間 3,502 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 93 ms
15,552 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 94 ms
15,592 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 93 ms
15,524 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 93 ms
15,560 KB
testcase_15 AC 93 ms
15,552 KB
testcase_16 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

require 'prime'

# 素数列挙
prime_generator = Prime::EratosthenesGenerator.new
@primes = []
begin ; @primes << prime_generator.next ; end while @primes[-1]<10000
@primes.reverse!

# dfs(num,you?) you?は勝つか?
@memo={}
def dfs(n,turn=true)
    return turn if n <= 1
    return @memo[[n,turn]] if @memo.key?([n,turn])
    res = !turn;
    @primes.each{|k|
        break if n-k<0
        a=dfs(n-k,!turn)
        res=((res^a)&turn)|(res&a)
    }
    return @memo[[n,turn]]=res
end

puts dfs(gets.to_i) ? "Win" : "Lose"

0