QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#213615#7560. Computer Networkucup-team1883#WA 1ms6020kbC++171.2kb2023-10-14 15:09:062023-10-14 15:09:07

Judging History

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

  • [2023-10-14 15:09:07]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:6020kb
  • [2023-10-14 15:09:06]
  • 提交

answer

#include <iostream>

const int inf = 2e9;
const int N = 1000005;

int a[N], b[N];
int n;

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);
  }
  long long ans = 1e12;
  for (int k = 0; k <= 31; ++k) {
    int mn = inf, mx = 0;
    for (int i = 1; i <= n; ++i) {
      int t = b[i] - (a[i] >> k);
      mn = std::min(mn, t);
      mx = std::max(mx, t);
    }
    if (mn < 0) continue;
    if (mx - mn > 1) continue;
    if (mx == mn) {
      ans = std::min(ans, 1ll * k);
      continue;
    }
    int l = 0, r = inf;
    for (int i = 1; i <= n; ++i) {
      int t = b[i] - (a[i] >> k);
      if (t == mx) {
        int ad = (1u << k) - (((1u << k) - 1) & a[i]);
        l = std::max(l, ad);
      } else {
        int ad = (1u << k) - 1 - (((1u << k) - 1) & a[i]);
        r = std::min(r, ad);
      }
    }
    if (l > r) continue;
    long long tmp = k + mn;
    for (int t = k; t >= 0; --t) {
      if ((l >> t & 1) != (r >> t & 1)) {
        ++tmp;
        break;
      }
      if (r >> t & 1) ++tmp;
    }
    ans = std::min(ans, tmp);
  }
  if (ans > 1e11) ans = -1;
  printf("%lld\n", ans);
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 5944kb

input:

3
2 3 4
1 2 3

output:

-1

result:

ok 1 number(s): "-1"

Test #3:

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

input:

2
65536 65537
1 2

output:

32

result:

ok 1 number(s): "32"

Test #4:

score: -100
Wrong Answer
time: 1ms
memory: 5876kb

input:

1
0
28

output:

0

result:

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