結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 83 ms
15,176 KB
testcase_04 AC 83 ms
15,084 KB
testcase_05 AC 83 ms
15,164 KB
testcase_06 AC 83 ms
15,168 KB
testcase_07 WA -
testcase_08 AC 81 ms
15,044 KB
testcase_09 AC 82 ms
15,256 KB
testcase_10 AC 83 ms
15,140 KB
testcase_11 AC 82 ms
15,080 KB
testcase_12 AC 83 ms
15,392 KB
testcase_13 AC 84 ms
15,220 KB
testcase_14 AC 83 ms
15,252 KB
testcase_15 AC 84 ms
15,276 KB
testcase_16 AC 83 ms
15,304 KB
testcase_17 WA -
testcase_18 AC 84 ms
15,136 KB
testcase_19 AC 84 ms
15,120 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

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

gets
c = scan

# End Of Line
abort if gets

c.keep_if{|e| e==1}

puts c.size.odd? ? 'A' : 'B'







exit
## ---------------------------------------------------------------------
## 観察用.愚直に解を求める.
## ----------------------------------------------------------------------

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

def solve(c, turn = :a_san)
    c.delete(0)
    
    # すべての箱が空になりキャンディーを取れなくなったほうが負け
    return flip(turn) if c.empty?
    
    c.each_index{|i|
        # i番目の箱から1つ取り出して相手の番に移った時,自分が必勝であればその手を打つ
        c[i] -= 1
        return turn if solve(c.clone, flip(turn)) == turn
        if turn == :b_san && 0 < c[i]
            # Bさんはもう1個とれる
            c[i] -= 1
            return turn if solve(c.clone, flip(turn)) == turn
            c[i] += 1
        end
        c[i] += 1
    }
    return flip(turn)
end

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