結果

問題 No.437 cwwゲーム
ユーザー はむ吉🐹
提出日時 2016-10-28 23:19:44
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 801 bytes
コンパイル時間 603 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 64,768 KB
最終ジャッジ日時 2024-11-24 06:20:32
合計ジャッジ時間 2,916 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 40 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env pypy3

import collections
import itertools
import sys


REC_LIMIT = 10000
UNDEF = -1


def is_cww(s):
    return len(s) == 3 and "0" != s[0] and s[0] != s[1] and s[1] == s[2]


def solve(n):
    dp = collections.defaultdict(lambda: UNDEF)

    def rec(x0):
        if dp[x0] != UNDEF:
            return dp[x0]
        score = 0
        for i, j, k in itertools.combinations(range(len(x0)), 3):
            y = x0[i] + x0[j] + x0[k]
            if not is_cww(y):
                continue
            x = x0[:i] + x0[j + 1:k] + x0[k + 1:]
            score = max(score, rec(x) + int(y))
        dp[x0] = score
        return score

    return rec(str(n))


def main():
    sys.setrecursionlimit(REC_LIMIT)
    n = int(input())
    print(solve(n))


if __name__ == '__main__':
    main()
0