結果
| 問題 |
No.437 cwwゲーム
|
| ユーザー |
conf
|
| 提出日時 | 2016-10-28 23:06:00 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,608 bytes |
| コンパイル時間 | 676 ms |
| コンパイル使用メモリ | 66,204 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-24 06:16:43 |
| 合計ジャッジ時間 | 1,771 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / 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 main(){
int64_t N;
int L=0;
cin>>N;
int a[12];
while(N){
a[L++]=N%10;
N/=10;
}
int64_t comb=(1LL<<3)-1;
int ans=0;
vector<int> V3;
while(comb<(1LL<<L)){
int CWW[3],cww=0;
for(int i=0;i<L;i++){
if(comb&(1LL<<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);
}
int64_t 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++){
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);
}
}
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;
}
conf