結果
問題 | No.437 cwwゲーム |
ユーザー | btk |
提出日時 | 2016-10-28 23:23:11 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 7 ms / 2,000 ms |
コード長 | 1,252 bytes |
コンパイル時間 | 1,782 ms |
コンパイル使用メモリ | 173,960 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-10-12 08:25:41 |
合計ジャッジ時間 | 2,886 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 41 |
ソースコード
#include<bits/stdc++.h> using namespace std; struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star; template<typename T> istream& operator>>(istream &is,vector<T> &v){ for(auto &it:v)is>>it; return is; } template<typename T>void chmin(T& a, T& b){a=min(a,b);} template<typename T>void chmax(T& a, T b){a=max(a,b);} typedef long long LL; LL calc(char a,char b,char c){ if(a=='0')return 0; if(b!=c||a==b)return 0; return (a-'0')*100+(b-'0')*10+(c-'0'); } int main(){ string S; cin>>S; int n=S.size(); LL res=0; vector<LL> dp(1<<n,0); vector<int> ord(1<<n,0); iota(ord.begin(),ord.end(),0); sort(ord.begin(),ord.end(),[&](int l,int r){ return __builtin_popcount(l)>__builtin_popcount(r);}); for(auto &bit:ord){ chmax(res,dp[bit]); for(int i=0;i<n;i++) if(bit&(1<<i)) for(int j=i+1;j<n;j++) if(bit&(1<<j)) for(int k=j+1;k<n;k++) if(bit&(1<<k)){ chmax(dp[bit-(1<<i)-(1<<j)-(1<<k)],dp[bit]+calc(S[i],S[j],S[k])); } } cout<<res<<endl; return 0; }