QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#206651 | #7560. Computer Network | ucup-team1264# | WA | 0ms | 3648kb | C++20 | 1.5kb | 2023-10-07 22:03:36 | 2023-10-07 22:03:36 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
#define int i64
void solve() {
int n;
cin >> n;
int ans = 1e18;
vector<int> a(n), b(n);
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++)
cin >> b[i];
for (int d = 0; d < 30; d++) {
int l = 0, r = 1e18;
for (int i = 0; i < n; i++) {
l = max(l, (b[i] << d) - a[i]);
r = min(r, ((b[i] + 1) << d) - 1 - a[i]);
}
if (l > r) continue;
int tmp = 1e18;
if (l >> d == r >> d) {
for (int now = l; now <= r; now += now & (-now)) {
tmp = min(tmp,
d + (now >> d) + popcount(now & ((1ull << d) - 1)));
}
} else {
int mid = (r >> d) << d;
for (int now = l; now < mid; now += now & (-now)) {
tmp = min(tmp,
d + (now >> d) + popcount(now & ((1ull << d) - 1)));
}
for (int now = mid; now <= r; now += now & (-now)) {
tmp = min(tmp,
d + (now >> d) + popcount(now & ((1ull << d) - 1)));
}
}
ans = min(ans, tmp);
}
if (ans >= 1e18) {
cout << -1 << n;
} else cout << ans << "\n";
}
#undef int
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3648kb
input:
5 1 2 3 4 5 6 6 6 6 7
output:
9
result:
ok 1 number(s): "9"
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3576kb
input:
3 2 3 4 1 2 3
output:
-13
result:
wrong answer 1st numbers differ - expected: '-1', found: '-13'