結果

問題 No.437 cwwゲーム
ユーザー imulan
提出日時 2016-12-02 23:48:57
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 1,083 bytes
コンパイル時間 1,618 ms
コンパイル使用メモリ 169,884 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-12 08:40:39
合計ジャッジ時間 2,834 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

int dp[8200]={0};

inline bool check(int a, int b, int c)
{
    if(a==0) return false;
    if(b!=c) return false;
    if(a==b) return false;
    return true;
}

inline int score(int a, int b, int c)
{
    return 100*a+10*b+c;
}

int main()
{
    string s;
    cin >>s;

    int L=s.size();
    vector<int> a(L);
    rep(i,L) a[i]=s[i]-'0';

    rep(mask,1<<L)
    {
        rep(k,L)if(!(mask>>k&1))rep(j,k)if(!(mask>>j&1))rep(i,j)if(!(mask>>i&1))
        {
            if(i==j || i==k || j==k) continue;
            if(!check(a[i],a[j],a[k])) continue;

            int nxmask = mask|(1<<i)|(1<<j)|(1<<k);
            dp[nxmask] = max(dp[nxmask], dp[mask]+score(a[i],a[j],a[k]));
        }
    }

    int ans=0;
    rep(i,1<<L) ans=max(ans,dp[i]);
    cout << ans << endl;
    return 0;
}
0