結果

問題 No.582 キャンディー・ボックス3
ユーザー maimai
提出日時 2017-04-14 00:27:55
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 675 bytes
コンパイル時間 59 ms
コンパイル使用メモリ 11,296 KB
実行使用メモリ 28,680 KB
最終ジャッジ日時 2023-09-27 04:00:40
合計ジャッジ時間 4,382 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 74 ms
15,224 KB
testcase_02 WA -
testcase_03 AC 81 ms
15,092 KB
testcase_04 AC 78 ms
15,156 KB
testcase_05 AC 77 ms
15,164 KB
testcase_06 AC 76 ms
15,140 KB
testcase_07 RE -
testcase_08 AC 78 ms
15,164 KB
testcase_09 AC 77 ms
15,116 KB
testcase_10 AC 76 ms
15,276 KB
testcase_11 AC 76 ms
15,312 KB
testcase_12 RE -
testcase_13 AC 519 ms
17,988 KB
testcase_14 AC 126 ms
17,552 KB
testcase_15 AC 984 ms
19,956 KB
testcase_16 AC 157 ms
18,460 KB
testcase_17 AC 82 ms
15,252 KB
testcase_18 RE -
testcase_19 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def scan; gets.chomp!.split.map(&:to_i); end

def flip(turn)
    turn == :a_san ? :b_san : :a_san
end

@memo={}
def dfs(c, turn = :a_san)
    c.delete(0)
    
    return flip(turn) if c.empty?
    
    return @memo[[c,turn]] if @memo[[c,turn]]
    
    c.each_index{|i|
        c[i] -= 1
        return @memo[[c,turn]]=turn if dfs(c.clone, flip(turn)) == turn
        if turn == :b_san && 0 < c[i]
            c[i] -= 1
            return @memo[[c,turn]]=turn if dfs(c.clone, flip(turn)) == turn
            c[i] += 1
        end
        c[i] += 1
    }
    return @memo[[c,turn]]=flip(turn)
end

gets
c = scan

# End Of Line
abort if gets

puts dfs(c) == :a_san ? 'A' : 'B'
0