CF949E Binary Cards 题解
首先有一个引理
:::info[引理1]
对于
接下来我们引入一个优化来让复杂度变正确。
我们在刚开始把
:::::info[复杂度证明]
先证正确性。
::::info[正确性证明]
:::info[右移]
我们在做完加
代码:
#include <bits/stdc++.h>
using namespace std;
namespace MySpace{
#define lowbit(x) (x&(-x))
#define sqrt sqrtl
using pii=pair<int,int>;
#define whileu(p) while (p--)
#define forl(a,b,c) for (auto a=b;a<=c;a=a+1)
inline void read() {}
template <typename T, typename... R>
inline void read(T &x,R &... oth){
x=0;T f=1;
char c=getchar();
while(c<'0' || c>'9') {
if(c=='-') f=-1;
c=getchar();
}
while(c>='0' && c<='9') x=(x<<1)+(x<<3)+(c&15),c=getchar();
x*=f;
read(oth...);
return;
}
template<typename T>
T qpow(T a,T n,T p){
T res=1;a%=p;
while (n){
if (n&1) res=1ll*res*a%p;
a=1ll*a*a%p;
n>>=1;
}
return res;
}
template<typename T>
T gcd(T a,T b){return (b>0?gcd(b,a%b):a);}
template<typename T>
T exgcd(T a,T b,T& x,T& y){
if (b<=0ll){
x=1ll,y=0ll;
return a;
}
T d=exgcd(b,a%b,y,x);
y-=(a/b)*x;
return d;
}
template<typename T>
T inv(T a,T p){
if (a==1) return 1ll;
T x,y;
if (exgcd(a,p,x,y)!=1ll) return -1ll;
else return (x+p)%p;
}
}
using namespace MySpace;
//const int INF=0x66CCFF66;
#ifndef ONLINE_JUDGE
#include "G:\CodeFloder\debug.h"
using namespace DEBUGs;
#endif
#define int long long
using vi=vector<int>;
const int maxn=1e5+5;
int n;
vi a,ans;
void does(vi& a){
//sort(a.begin(),a.end());
for (auto &i:a) i>>=1;
a.erase(unique(a.begin(),a.end()),a.end());
return;
}
vi dfs(int x){
if (x>19) return vi(0);
for (auto i:a) if (i&1){
vi tmp=a;
for (auto &i:a) if (i&1) i+=1;
does(a);
vi ta=dfs(x+1);
a=tmp;
for (auto &i:a) if (i&1) i-=1;
does(a);
vi tb=dfs(x+1);
ta.push_back(-(1ll<<x));
tb.push_back((1ll<<x));
return ta.size()<tb.size()?ta:tb;
}
does(a);
return dfs(x+1);
}
signed main(){
read(n);
for (int i=1;i<=n;i++) {
int tmp;read(tmp);
a.push_back(tmp);
}
sort(a.begin(),a.end());
ans=dfs(0);
printf("%d\n",ans.size());
for (auto i:ans) printf("%d ",i);
return 0;
}