結果
問題 |
No.437 cwwゲーム
|
ユーザー |
![]() |
提出日時 | 2016-10-28 23:11:45 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 781 bytes |
コンパイル時間 | 307 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 64,256 KB |
最終ジャッジ日時 | 2024-11-24 06:19:50 |
合計ジャッジ時間 | 3,703 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 39 WA * 2 |
ソースコード
#!/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] != 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()