結果

問題 No.437 cwwゲーム
ユーザー nebukuro09
提出日時 2016-10-28 23:13:57
言語 Python2
(2.7.18)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 442 bytes
コンパイル時間 302 ms
コンパイル使用メモリ 6,912 KB
実行使用メモリ 6,528 KB
最終ジャッジ日時 2024-10-12 08:24:50
合計ジャッジ時間 1,987 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import combinations

S = raw_input()
N = len(S)

mem = {}
def rec(b):
    if b in mem:
        return mem[b]
    L = [i for i in xrange(N) if (1<<i) & b == 0]
    tmp_ans = 0
    for c, w1, w2 in combinations(L, 3):
        if S[c] != '0' and S[w1] == S[w2] and S[c] != S[w1]:
            tmp_ans = max(tmp_ans, rec(b + (1<<c) + (1<<w1) + (1<<w2)) + int(S[c]+S[w1]+S[w2]))
    mem[b] = tmp_ans
    return tmp_ans

print rec(0)
0