結果

問題 No.437 cwwゲーム
ユーザー fine
提出日時 2016-10-28 23:08:52
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,028 bytes
コンパイル時間 1,811 ms
コンパイル使用メモリ 169,296 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-24 06:52:00
合計ジャッジ時間 4,000 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 40 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;

string n;
int l;

int dfs(int c, int score, vector<int> memo) {
    if (c == l / 3 + 1) return score;
    int ret = 0;
    for (int i = 0; i < l; i++) {
        if (memo[i] != 0) continue;
        for (int j = i + 1; j < l; j++) {
            if (memo[j] != 0) continue;
            for (int k = j + 1; k < l; k++) {
                if (memo[k] != 0) continue;
                int x;
                if (n[i] == n[j] || n[j] != n[k]) x = 0;
                else x = (n[i] - '0') * 100 + (n[j] - '0') * 10 + (n[k] - '0');
                memo[i] = c;
                memo[j] = c;
                memo[k] = c;
                ret = max(ret, dfs(c + 1, score + x, memo));
                memo[i] = 0;
                memo[j] = 0;
                memo[k] = 0;
            }
        }
    }
    return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    l = n.length();
    vector<int> memo(l, 0);
    cout << dfs(1, 0, memo) << endl;
    return 0;
}
0