QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#206651#7560. Computer Networkucup-team1264#WA 0ms3648kbC++201.5kb2023-10-07 22:03:362023-10-07 22:03:36

Judging History

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

  • [2023-10-07 22:03:36]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3648kb
  • [2023-10-07 22:03:36]
  • 提交

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();
    }
}

详细

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'