結果

問題 No.437 cwwゲーム
ユーザー neko_the_shadowneko_the_shadow
提出日時 2016-10-29 22:21:27
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 780 bytes
コンパイル時間 88 ms
コンパイル使用メモリ 11,492 KB
実行使用メモリ 19,844 KB
最終ジャッジ日時 2023-08-16 11:09:29
合計ジャッジ時間 19,024 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
19,432 KB
testcase_01 AC 79 ms
15,120 KB
testcase_02 AC 130 ms
15,312 KB
testcase_03 AC 82 ms
15,244 KB
testcase_04 AC 78 ms
15,124 KB
testcase_05 TLE -
testcase_06 TLE -
testcase_07 TLE -
testcase_08 TLE -
testcase_09 TLE -
testcase_10 TLE -
testcase_11 TLE -
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

class Solver

    def initialize(n)
        @digits = []
        while n > 0
            @digits << n % 10
            n /= 10
        end
        @digits.reverse!
    end

    def f(bit)
        idxs = (0...@digits.size).each_with_object([]){|idx, arr| arr << idx if bit & (1 << idx) == 0}

        return 0 if idxs.size < 3
        
        scores = []
        idxs.combination(3) do |i, j, k|
            x = 100 * @digits[i] + 10 * @digits[j] + @digits[k]
            b = bit | (1 << i) | (1 << j) | (1 << k)
            
            score = f(b)
            score += x if @digits[i] != 0 && @digits[j] == @digits[k] && @digits[i] != @digits[j]

            scores << score
        end
        scores.max
    end
end


n = STDIN.gets.to_i
solver = Solver.new(n)
p solver.f(0)
0