結果
問題 |
No.437 cwwゲーム
|
ユーザー |
![]() |
提出日時 | 2016-10-28 23:14:09 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,769 bytes |
コンパイル時間 | 556 ms |
コンパイル使用メモリ | 65,972 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-24 06:20:08 |
合計ジャッジ時間 | 1,884 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 WA * 1 |
other | AC * 30 WA * 10 RE * 1 |
ソースコード
#include <iostream> #include <algorithm> #include <vector> #include <queue> using namespace std; typedef pair<int,int> P; int memo[1LL<<12]; int main(){ int64_t N; int L=0; cin>>N; int a[12]; while(N){ a[L++]=N%10; N/=10; } int ans=0; vector<int> V3,V6,V9; if(L>=3){ int comb=(1<<3)-1; int ans=0; 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; } } if(L>=6){ for(int i=0;i<V3.size();i++){ for(int j=i+1;j<V3.size();j++){ if(V3[i]&V3[j]) continue; int sum=memo[V3[i]]+memo[V3[j]]; memo[V3[i]|V3[j]]=max(memo[V3[i]|V3[j]],sum); V6.push_back(V3[i]|V3[j]); ans=max(ans,sum); } } } if(L>=9){ 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; }