QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#305816#7560. Computer NetworkNemanjaSo2005WA 1ms5848kbC++14848b2024-01-16 01:16:032024-01-16 01:16:04

Judging History

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

  • [2024-01-16 01:16:04]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5848kb
  • [2024-01-16 01:16:03]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=1e6+5;
ll A[maxn],B[maxn];
ll N;
int main(){
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   cin>>N;
   for(int i=1;i<=N;i++)
      cin>>A[i];
   for(int i=1;i<=N;i++)
      cin>>B[i];
   ll res=1e18;
   for(int k=0;k<=32;k++){
      ll l=-1e18,r=1e18;
      for(int i=1;i<=N;i++){
         l=max(l,B[i]*(1<<k)-A[i]);
         r=min(r,B[i]*(1<<k)+(1<<k)-1-A[i]);
      }
      if(r<0 or r<l)
         continue;
      if(l==0){
         res=min(res,(ll)k);
         continue;
      }
      while(l<=r){
			res=min(res,l/(1ll<<k)+__builtin_popcount(l&((1ll<<k)-1))+k);
			if(l==0)break;
			l+=l&-l;
		}
   }
   if(res<1e18)
      cout<<res<<"\n";
   else
      cout<<"-1\n";
   return 0;
}
/*
5
1 2 3 4 5
6 6 6 6 7
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 5848kb

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: 5768kb

input:

3
2 3 4
1 2 3

output:

-1

result:

ok 1 number(s): "-1"

Test #3:

score: 0
Accepted
time: 0ms
memory: 5560kb

input:

2
65536 65537
1 2

output:

32

result:

ok 1 number(s): "32"

Test #4:

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

input:

1
0
28

output:

28

result:

ok 1 number(s): "28"

Test #5:

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

input:

1
249912
43

output:

26

result:

ok 1 number(s): "26"

Test #6:

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

input:

2
52522336 155670
52532336 165670

output:

37

result:

wrong answer 1st numbers differ - expected: '10000', found: '37'