結果
問題 |
No.437 cwwゲーム
|
ユーザー |
![]() |
提出日時 | 2016-10-28 23:23:43 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,607 bytes |
コンパイル時間 | 564 ms |
コンパイル使用メモリ | 66,116 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-24 06:21:25 |
合計ジャッジ時間 | 1,899 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 40 RE * 1 |
ソースコード
#include <iostream> #include <algorithm> #include <vector> #include <queue> using namespace std; typedef pair<int,int> P; int memo[1<<12]; int a[12]; 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; }