QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#205140 | #7560. Computer Network | ucup-team1069# | WA | 1ms | 7716kb | C++23 | 2.1kb | 2023-10-07 14:59:25 | 2023-10-07 14:59:26 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 200;
int n, a[N], b[N], u[N];
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
int Mx = 0, Mn = 2e9;
for (int i = 1; i <= n; ++i) {
cin >> b[i];
Mx = max(Mx, b[i] - a[i]);
Mn = min(Mn, b[i] - a[i]);
}
int Ans = 2e9;
if (Mx == Mn) {
Ans = Mx;
}
for (int i = 1, now = 0; i <= 31; ++i) {
vector<pair<int, int>> v;
for (int j = 1; j <= n; ++j) {
v.push_back({a[j] % (1 << i), j});
}
sort(v.begin(), v.end());
int mx = 0, mn = 2e9;
for (auto [x, j] : v) {
int r = (b[j] - a[j] / (1 << i));
mx = max(mx, r);
mn = min(mn, r);
}
if (mx > mn + 1) continue;
if (mn < 0) continue;
if (mn == mx) {
Ans = min(Ans, i + mn);
continue;
}
for (int j = 1; j <= n; ++j) u[j] = 0;
for (auto [x, j] : v) {
int r = (b[j] - a[j] / (1 << i));
if (r == mx) {
u[j] = 1;
}
}
int last = 0, F = 1, p0 = -1, p1 = -1;
for (auto [x, j] : v) {
if (u[j] == 0 && last == 1) {
F = 0;
break;
}
last = u[j];
if (u[j] == 0) p0 = x;
if (u[j] == 1 && p1 == -1) p1 = x;
}
if (!F) continue;
if (p0 == -1 || p1 == -1) continue;
int ans = mn;
if (p0 <= p1) continue;
for (int j = 1; j <= i; ++j) {
if (p0 / 2 == p1 / 2) {
p0++;
p1++;
p0 /= 2;
p1 /= 2;
ans += 2;
}
else {
p0 /= 2;
p1 /= 2;
ans++;
}
}
Ans = min(Ans, ans);
}
if (Ans == 2e9) {
cout << -1 << '\n';
}
else {
cout << Ans << '\n';
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 7716kb
input:
5 1 2 3 4 5 6 6 6 6 7
output:
-1
result:
wrong answer 1st numbers differ - expected: '9', found: '-1'