QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#206316#7560. Computer Networkucup-team206#WA 1ms6028kbC++141.2kb2023-10-07 19:59:472023-10-07 19:59:47

Judging History

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

  • [2023-10-07 19:59:47]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:6028kb
  • [2023-10-07 19:59:47]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int n, a[N], b[N];
inline int Calc(int k, int a1) {
    int mn = 0, mx = (1 << k) - 1;
    for (int i = 1; i <= n; ++i) {
        int na = a[i] >> k;
        int target = b[i] - b[1] + a1;
        // printf("%d %d\n", na, target);
        if (target != na && target != na + 1) return 2e9;
        int val = a[i] & ((1 << k) - 1);
        if (target == na) mx = min(mx, (1 << k) - val - 1);
        else mn = max(mn, (1 << k) - val);
        // printf("=> %d %d\n", mn, mx);
        if (mn > mx) return 2e9;
    }
    // printf("%d %d\n", mn, mx);
    int ans = 0;
    for (int i = k - 1; ~i; --i) {
        if ((mx >> i & 1) == (mn >> i & 1)) ans += (mx >> i & 1);
        else { ++ans; break; }
    }
    return ans;
}
int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) scanf("%d", a + i);
    for (int i = 1; i <= n; ++i) scanf("%d", b + i);
    int ans = 2e9;
    for (int i = 0; i <= 30; ++i) {
        for (int d = 0; d < 2; ++d) {
            int na = a[1] >> i;
            if (na + d <= b[1]) ans = min(ans, i + b[1] - (na + d) + Calc(i, na + d)); 
        }
    }
    if (ans == 2e9) ans = -1;
    printf("%d\n", ans);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

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

input:

3
2 3 4
1 2 3

output:

-1

result:

ok 1 number(s): "-1"

Test #3:

score: 0
Accepted
time: 1ms
memory: 5824kb

input:

2
65536 65537
1 2

output:

32

result:

ok 1 number(s): "32"

Test #4:

score: 0
Accepted
time: 1ms
memory: 5964kb

input:

1
0
28

output:

28

result:

ok 1 number(s): "28"

Test #5:

score: 0
Accepted
time: 1ms
memory: 5888kb

input:

1
249912
43

output:

26

result:

ok 1 number(s): "26"

Test #6:

score: 0
Accepted
time: 1ms
memory: 6028kb

input:

2
52522336 155670
52532336 165670

output:

10000

result:

ok 1 number(s): "10000"

Test #7:

score: -100
Wrong Answer
time: 0ms
memory: 5840kb

input:

2
141839218 538313890
17731054 67290388

output:

1156

result:

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