QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#205109#7560. Computer Networkucup-team1448#WA 1ms5840kbC++141.3kb2023-10-07 14:53:442023-10-07 14:53:46

Judging History

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

  • [2023-10-07 14:53:46]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5840kb
  • [2023-10-07 14:53:44]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
template <typename T> void rd(T &x) {
    x = 0;
    int f = 1;
    char c = getchar();
    while (c < '0' || c > '9') {
        if (c == '-') f = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9') {
        x = x * 10 + c - 48;
        c = getchar();
    }
    x *= f;
}
template <typename T, typename... T2> void rd(T &x, T2 &...y) {
    rd(x), rd(y...);
}

using ll = long long;
const int Nmax = 1e6 + 5, Vmax = 30;
const ll inf = 1e18;
int n;
ll a[Nmax], b[Nmax], ans = inf;

int main() {
    rd(n);
    for (int i = 1; i <= n; ++i)
        rd(a[i]);
    for (int i = 1; i <= n; ++i)
        rd(b[i]);
    for (int i = 0; i < Vmax; ++i) {
        ll l = 0, r = inf;
        for (int j = 1; j <= n; ++j) {
            l = max(l, (b[j] << i) - a[j]);
            r = min(r, ((b[j] + 1) << i) - a[j]);
            // printf("<%d %d>\n", (b[j] << i) - a[j], ((b[j] + 1) << i) -
            // a[j]);
        }
        // printf("%lld %lld\n", l, r);
        ll mn = inf;
        if (l) {
            for (; l < r; l += l & -l)
                mn = min(mn,
                         (l >> i) + __builtin_popcount(l & ((1ll << i) - 1)));
        } else {
            mn = 0;
        }
        ans = min(ans, mn + i);
    }
    printf("%lld", ans == inf ? -1 : ans);
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 5816kb

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: 1ms
memory: 5840kb

input:

3
2 3 4
1 2 3

output:

0

result:

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