結果

問題 No.437 cwwゲーム
ユーザー 🍡yurahuna🍡yurahuna
提出日時 2016-10-25 15:30:45
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 101 ms / 2,000 ms
コード長 673 bytes
コンパイル時間 96 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-10-12 08:19:48
合計ジャッジ時間 3,017 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

def cww(a, b, c):
    if a != 0 and a != b and b == c:
        return 100 * a + 10 * b + c
    return -1

s = [int(c) for c in input()]
n = len(s)
dp = [-1] * (1 << n)
dp[0] = 0
for state in range(1 << n):
    if dp[state] == -1:
        continue
    for i in range(n):
        for j in range(i + 1, n):
            for k in range(j + 1, n):
                if ((state >> i) & 1) | ((state >> j) & 1) | ((state >> k) & 1):
                    continue
                x = cww(s[i], s[j], s[k])
                if x != -1:
                    nxstate = state | (1 << i) | (1 << j) | (1 << k)
                    dp[nxstate] = max(dp[nxstate], dp[state] + x)

print(max(dp))
0