結果
問題 | No.437 cwwゲーム |
ユーザー | conf |
提出日時 | 2016-10-28 23:25:45 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,607 bytes |
コンパイル時間 | 972 ms |
コンパイル使用メモリ | 76,492 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-12 08:25:58 |
合計ジャッジ時間 | 2,187 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 41 |
ソースコード
#include <iostream> #include <algorithm> #include <vector> #include <queue> using namespace std; typedef pair<int,int> P; int memo[1<<13]; int a[13]; int main(){ int64_t N; int L=0; cin>>N; while(N){ a[L++]=N%10; N/=10; } int comb=(1<<3)-1; int ans=0; vector<int> V3; while(comb<(1<<L)){ int CWW[3],cww=0; for(int i=0;i<L;i++){ if(comb&(1<<i))CWW[cww++]=a[i]; } if(CWW[0]==CWW[1]&&CWW[1]!=CWW[2]&&CWW[2]){ memo[comb]=CWW[2]*100+CWW[1]*10+CWW[0]; ans=max(ans,memo[comb]); V3.push_back(comb); } int x = comb&-comb, y=comb+x; comb=((comb&~y)/x>>1)|y; } vector<int> V6; for(int i=0;i<V3.size();i++){ for(int j=i+1;j<V3.size();j++){ int v3i=V3[i],v3j=V3[j]; if(v3i&v3j) continue; int sum=memo[v3i]+memo[v3j]; memo[v3i|v3j]=max(memo[v3i|v3j],sum); V6.push_back(v3i|v3j); ans=max(ans,sum); } } vector<int> V9; for(auto v3:V3){ for(auto v6:V6){ if(v3&v6) continue; int sum=memo[v3]+memo[v6]; memo[v3|v6]=max(memo[v3|v6],sum); V9.push_back(v3|v6); ans=max(sum,ans); } } if(L>=12){ for(auto v3:V3){ for(auto v9:V9){ if(v3&v9)continue; int sum=memo[v3]+memo[v9]; memo[v3|v9]=max(memo[v3|v9],sum); ans=max(sum,ans); } } } cout<<ans<<endl; return 0; }