淘汰(Easy ver.)题解
Cosmos_zzx · · 题解
这里提供一种乱搞做法。
我们可以发现:对于一个
于是,对于一个
#include<bits/stdc++.h>
#define int long long
using namespace std;
typedef long long ll;
#define getchar_unlocked() getchar()
inline int read() {int x=0,ff=1;char ch=getchar_unlocked();while(ch<48||ch>57) {if(ch==45)ff=-1;ch=getchar_unlocked();}while(ch>=48&&ch<=57) x=(x<<3)+(x<<1)+(ch^48),ch=getchar_unlocked();return x*ff;}
inline void write(int x,char ch){if(!x){putchar(48),putchar(ch);return;}if(x<0)putchar(45),x=-x;char a[20];int i=0;while(x)a[++i]=x%10+48,x/=10;for(;i;i--)putchar(a[i]);putchar(ch);}
const int N=1e6+114;
int T;
int x,y,a,b,c,d;
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin>>T;
while(T--)
{
cin>>x>>y>>a>>b>>c>>d;
if(x==y)cout<<0<<endl;
else if((x&a)==y)cout<<c<<endl;
else if((x|b)==y)cout<<d<<endl;
else
{
int sum=0,ans=1e18;bool flag=0;
int xx=x;
for(int i=1;i<=2000;i++)
{
if(i%2)x&=a,sum+=c;
else x|=b,sum+=d;
if(x==y)
{
flag=1;
break;
}
}
ans=min(ans,sum);
sum=0;x=xx;
for(int i=1;i<=2000;i++)
{
if(i%2==0)x&=a,sum+=c;
else x|=b,sum+=d;
if(x==y)
{
flag=1;
break;
}
}
ans=min(ans,sum);
if(!flag)cout<<-1<<endl;
else cout<<ans<<endl;
}
}
return 0;
}
/*
1
5
2 4 2 5 2
1 3 2 5 4
*/