QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#204638 | #7560. Computer Network | ucup-team052# | TL | 1ms | 5904kb | C++14 | 1.7kb | 2023-10-07 13:32:36 | 2023-10-07 13:32:37 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
using namespace std;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef long long ll;
template <typename _T>
inline void read(_T &f) {
f = 0; _T fu = 1; char c = getchar();
while (c < '0' || c > '9') { if (c == '-') { fu = -1; } c = getchar(); }
while (c >= '0' && c <= '9') { f = (f << 3) + (f << 1) + (c & 15); c = getchar(); }
f *= fu;
}
template <typename T>
void print(T x) {
if (x < 0) putchar('-'), x = -x;
if (x < 10) putchar(x + 48);
else print(x / 10), putchar(x % 10 + 48);
}
template <typename T>
void print(T x, char t) {
print(x); putchar(t);
}
const ll INF = 8e18;
const int N = 1e6 + 5;
int a[N], b[N];
int n;
ll ans = INF;
int main() {
read(n);
for (int i = 1; i <= n; i++) read(a[i]);
for (int i = 1; i <= n; i++) read(b[i]);
for (int bit = 0; bit <= 30; bit++) {
ll l = 0, r = INF;
for (int i = 1; i <= n; i++) {
ll bl = (ll)b[i] << bit, br = ((ll)(b[i] + 1) << bit) - 1;
l = max(l, bl - a[i]); r = min(r, br - a[i]);
}
if (l <= r) {
ll tmp = l >> bit;
r -= (l >> bit) << bit;
l -= (l >> bit) << bit;
int ret = __builtin_popcountll(l);
while (1) {
l += (l & -l);
if (l > r) break;
ret = min(ret, __builtin_popcountll(l));
}
ans = min(ans, ret + bit + tmp);
}
}
if (ans == INF) ans = -1;
print(ans, '\n');
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5904kb
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: 0ms
memory: 5664kb
input:
3 2 3 4 1 2 3
output:
-1
result:
ok 1 number(s): "-1"
Test #3:
score: 0
Accepted
time: 1ms
memory: 5868kb
input:
2 65536 65537 1 2
output:
32
result:
ok 1 number(s): "32"
Test #4:
score: -100
Time Limit Exceeded
input:
1 0 28