# 题解

$$O(a_i ^{\log_2 3})$$

# 代码

#pragma GCC optimize("Ofast","inline")
#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof (x))
#define For(i,a,b) for (int i=a;i<=b;i++)
#define Fod(i,b,a) for (int i=b;i>=a;i--)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
#define _SEED_ ('C'+'L'+'Y'+'A'+'K'+'I'+'O'+'I')
#define outval(x) printf(#x" = %d\n",x)
#define outvec(x) printf("vec "#x" = ");for (auto _v : x)printf("%d ",_v);puts("")
#define outtag(x) puts("----------"#x"----------")
#define outarr(a,L,R) printf(#a"[%d...%d] = ",L,R);\
For(_v2,L,R)printf("%d ",a[_v2]);puts("");
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector <int> vi;
LL read(){
LL x=0,f=0;
char ch=getchar();
while (!isdigit(ch))
f|=ch=='-',ch=getchar();
while (isdigit(ch))
x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
return f?-x:x;
}
const int N=1<<18;
const LL INF=1e18;
int n,t=18;
int a[N],vis[N];
int And=(1<<t)-1;
LL dp[N];
int main(){
n=read();
For(i,1,n){
a[i]=read();
And&=a[i];
}
For(i,1,n)
a[i]^=And;
For(i,1,n)
vis[(N-1)^a[i]]=1;
For(i,0,t-1)
For(j,0,N-1)
if (~j>>i&1)
vis[j]|=vis[j|1<<i];
For(i,0,N-1)
dp[i]=INF;
For(i,1,n)
dp[a[i]]=a[i];
Fod(i,N-1,0){
if (dp[i]>=dp[0])
continue;
for (int j=i;j>0;j=(j-1)&i)
if (vis[j])
dp[i^j]=min(dp[i^j],dp[i]+(i^j));
}
cout<<(LL)And*n+dp[0]<<endl;
return 0;
}


posted @ 2019-03-23 19:44 -zhouzhendong- 阅读(...) 评论(...) 编辑 收藏