QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#210001#7560. Computer Networkucup-team1479WA 1ms9864kbC++172.1kb2023-10-10 21:29:042023-10-10 21:29:04

Judging History

你现在查看的是最新测评结果

  • [2023-10-10 21:29:04]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:9864kb
  • [2023-10-10 21:29:04]
  • 提交

answer

#include<bits/stdc++.h>
#define RI int
#define err puts("asd")
#define ll long long
#define ull unsigned long long
#define LL __int128
#define db double
#define mk make_pair
#define FL fflush(stdout)
#define eb emplace_back
#define FR(u,v) for(int i=h[u],v=a[i].t;i;i=a[i].n,v=a[i].t)
#define FB(x,z,y) for(int y=LG[(x)&-(x)],z=x;z;z^=z&-z,y=LG[z&-z])
#define FS(x,y) for(int y=(x);y;y=(y-1)&(x))
#define mem(a,b) memset(a,b,sizeof a)
#define yes puts("Yes")
#define no puts("No")
#define gg puts("-1")
#define vc vector
#define ex exit(0)
#define fi first
#define se second
#define int long long
//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
using namespace std;

const db eps=1e-10;
const int inf=2e9+5;
const ll INF=1e18;
const int mod=998244353;

inline ll power(ll x,int y){
	ll t=1;
	while(y){
		if(y&1) t=t*x%mod;
		x=x*x%mod;y>>=1;
	}
	return t;
}

inline void gt(int &x,int &y){if(x>y) swap(x,y);}

inline void cmax(int &x,int y){x<y?x=y:0;}

inline void cmin(int &x,int y){x>y?x=y:0;}

inline void AD(int &x,int y){x+=y;if(x>=mod) x-=mod;}

inline ll read(){
	ll s=0;char c=getchar();bool f=0;
	while(c<'0'||c>'9'){if(c=='-') f=1;c=getchar();}
	while(c>='0'&&c<='9') s=(s<<1)+(s<<3)+c-48,c=getchar();
	return f?-s:s;
}

const int N=1e6+5;

int n,a[N],b[N],c[N],A[N],d[N],ans=INF;

signed main(){
	ll op,x=0,y=0,z=0,u=0,v=0,l,r;
//	freopen("1.in","r",stdin);
//	freopen("1.out","w",stdout);
	n=read();
	for(RI i=1;i<=n;++i) a[i]=read();
	for(RI i=1;i<=n;++i) b[i]=read();
	for(RI k=0;k<=30;++k){
		z=INF;bool ok=1;v=1<<k;
		for(RI i=1;i<=n;++i) c[i]=b[i]-(a[i]>>k),cmin(z,c[i]);
		if(z<0) continue;
		l=0;r=(1<<k)-1;u=1;
		for(RI i=1;i<=n;++i){
			if(c[i]!=z){
				u=0;
				if(c[i]!=z+1){ok=0;continue;}
				cmax(l,v-(a[i]%v));
			}
			else{
				cmin(r,v-(a[i]%v)-1);
			}
		}
		if(!ok||l>r) continue;
		x=0;
		for(RI i=k;i>=0;--i){
			if((r>>i&1)^(l>>i&1)) break;
			x+=r>>i&1;
		}
		cmin(x,__builtin_popcount(l));
		//cout<<x<<' '<<k<<' '<<z<<' '<<l<<' '<<r<<endl;
		cmin(ans,k+x+z-u);
	}
	if(ans==INF) gg;
	else cout<<ans;
	return 0;
}
















Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 9820kb

input:

5
1 2 3 4 5
6 6 6 6 7

output:

9

result:

ok 1 number(s): "9"

Test #2:

score: 0
Accepted
time: 1ms
memory: 9800kb

input:

3
2 3 4
1 2 3

output:

-1

result:

ok 1 number(s): "-1"

Test #3:

score: 0
Accepted
time: 1ms
memory: 9864kb

input:

2
65536 65537
1 2

output:

32

result:

ok 1 number(s): "32"

Test #4:

score: -100
Wrong Answer
time: 1ms
memory: 9796kb

input:

1
0
28

output:

27

result:

wrong answer 1st numbers differ - expected: '28', found: '27'