結果

問題 No.437 cwwゲーム
ユーザー vjudge1
提出日時 2025-08-24 12:02:34
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
RE  
実行時間 -
コード長 1,220 bytes
コンパイル時間 1,306 ms
コンパイル使用メモリ 162,984 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-08-24 12:02:38
合計ジャッジ時間 3,074 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 40 RE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

# include <bits/stdc++.h>
# define int long long
# define FILE(x) freopen(x ".in", "r", stdin); freopen(x ".out", "w", stdout);
using namespace std;
int n;
string s;
int a[20];
int f[5005];
int ans;
void solve()
{
    cin >> s;
    n = s.size();
    for (int i = 0; i < n; i ++)
    {
        a[i] = s[i] - '0';
    }
    fill(f + 1, f + 1 + n, -1e18);
    for (int s = 0; s < (1 << n); s ++)
    {
        if (f[s] == -1e18) continue;
        for (int i = 0; i < n; i ++)
        {
            if (!a[i]) continue;
            for (int j = i + 1; j < n; j ++)
            {
                for (int k = j + 1; k < n; k ++)
                {
                    if (a[j] != a[k]) continue;
                    if (a[i] == a[j]) continue;
                    if ((s & ((1 << i) | (1 << j) | (1 << k))) == 0)
                    {
                        int ns = s | (1 << i) | (1 << j) | (1 << k);
                        f[ns] = max(f[ns], f[s] + a[i] * 100 + a[j] * 11);
                    }
                }
            }
        }
    }
    cout << *max_element(f, f + (1 << n));
}
signed main()
{
    ios :: sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int T = 1;
    while (T --) solve();
    return 0;
}
0