結果

問題 No.437 cwwゲーム
ユーザー はむ吉🐹はむ吉🐹
提出日時 2016-10-29 15:48:09
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,107 bytes
コンパイル時間 108 ms
コンパイル使用メモリ 10,820 KB
実行使用メモリ 8,644 KB
最終ジャッジ日時 2023-08-16 06:43:37
合計ジャッジ時間 2,437 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,236 KB
testcase_01 AC 17 ms
8,228 KB
testcase_02 WA -
testcase_03 AC 16 ms
8,272 KB
testcase_04 AC 16 ms
8,260 KB
testcase_05 AC 17 ms
8,180 KB
testcase_06 AC 19 ms
8,328 KB
testcase_07 AC 27 ms
8,556 KB
testcase_08 AC 21 ms
8,288 KB
testcase_09 AC 26 ms
8,644 KB
testcase_10 AC 26 ms
8,568 KB
testcase_11 AC 17 ms
8,156 KB
testcase_12 AC 18 ms
8,172 KB
testcase_13 AC 18 ms
8,336 KB
testcase_14 AC 18 ms
8,312 KB
testcase_15 AC 28 ms
8,528 KB
testcase_16 AC 17 ms
8,208 KB
testcase_17 AC 17 ms
8,200 KB
testcase_18 AC 18 ms
8,208 KB
testcase_19 AC 16 ms
8,208 KB
testcase_20 AC 16 ms
8,224 KB
testcase_21 AC 16 ms
8,180 KB
testcase_22 AC 16 ms
8,240 KB
testcase_23 AC 17 ms
8,204 KB
testcase_24 AC 16 ms
8,172 KB
testcase_25 AC 17 ms
8,284 KB
testcase_26 AC 17 ms
8,240 KB
testcase_27 AC 17 ms
8,160 KB
testcase_28 AC 16 ms
8,160 KB
testcase_29 AC 17 ms
8,292 KB
testcase_30 AC 16 ms
8,264 KB
testcase_31 AC 16 ms
8,240 KB
testcase_32 AC 16 ms
8,288 KB
testcase_33 AC 17 ms
8,224 KB
testcase_34 AC 16 ms
8,208 KB
testcase_35 AC 16 ms
8,232 KB
testcase_36 AC 16 ms
8,160 KB
testcase_37 AC 16 ms
8,252 KB
testcase_38 AC 16 ms
8,288 KB
testcase_39 AC 16 ms
8,160 KB
testcase_40 AC 16 ms
8,160 KB
testcase_41 AC 17 ms
8,300 KB
testcase_42 WA -
testcase_43 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3

import itertools
import sys


REC_LIMIT = 10000


def cww_score(x):
    if x // 1000 > 0:
        return
    c, ww = divmod(x, 100)
    if c == 0:
        return
    w, m = divmod(ww, 11)
    if m != 0 or c == w:
        return
    else:
        return x


def compute_maximum_score(n):
    a = [int(c) for c in str(n)]
    all_digits = frozenset(range(len(a)))
    memo = dict()

    def rec(used_digits):
        if used_digits in memo:
            return memo[used_digits]
        res = 0
        unused_digits = all_digits - used_digits
        for i, j, k in itertools.combinations(unused_digits, 3):
            cww = 100 * a[i] + 10 * a[j] + a[k]
            score = cww_score(cww)
            if score is None:
                continue
            new_used_digits = used_digits | {i, j, k}
            res = max(res, rec(new_used_digits) + score)
        memo[used_digits] = res
        return res

    return rec(frozenset())


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


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