QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#204713 | #7560. Computer Network | ucup-team866# | WA | 1ms | 6040kb | C++14 | 740b | 2023-10-07 13:45:14 | 2023-10-07 13:45:14 |
Judging History
answer
#include <bits/stdc++.h>
#include <climits>
using namespace std;
typedef long long ll;
const int N = 1e6 + 6;
int n, a[N], b[N]; ll ans = LLONG_MAX;
int main() {
cin >> n;
for (int i=1; i<=n; i++)
scanf ("%d", &a[i]);
for (int i=1; i<=n; i++)
scanf ("%d", &b[i]);
for (int d=0; d<=31; d++) {
ll L = 0, R = LLONG_MAX;
for (int i=1; i<=n; i++)
L = max(L, (1ll * b[i] << d) - a[i]),
R = min(R, (1ll * b[i] + 1 << d) - a[i] - 1);
if (L > R) continue;
int t = 62;
for (; ~t; t--) if (L >> t & 1 ^ R >> t & 1) break;
if (~ t && (L & (1ll << t) - 1)) L = L >> t << t | 1;
ans = min(ans, (L >> d) + __builtin_popcountll(L & (1 << d) - 1) + d);
} cout << (ans == LLONG_MAX ? - 1 : ans) << endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 6032kb
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: 5752kb
input:
3 2 3 4 1 2 3
output:
-1
result:
ok 1 number(s): "-1"
Test #3:
score: 0
Accepted
time: 1ms
memory: 6040kb
input:
2 65536 65537 1 2
output:
32
result:
ok 1 number(s): "32"
Test #4:
score: 0
Accepted
time: 1ms
memory: 5648kb
input:
1 0 28
output:
28
result:
ok 1 number(s): "28"
Test #5:
score: 0
Accepted
time: 1ms
memory: 5672kb
input:
1 249912 43
output:
26
result:
ok 1 number(s): "26"
Test #6:
score: 0
Accepted
time: 1ms
memory: 6040kb
input:
2 52522336 155670 52532336 165670
output:
10000
result:
ok 1 number(s): "10000"
Test #7:
score: -100
Wrong Answer
time: 1ms
memory: 5812kb
input:
2 141839218 538313890 17731054 67290388
output:
1028
result:
wrong answer 1st numbers differ - expected: '1155', found: '1028'