QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#293284#7560. Computer NetworkOAleksaWA 0ms3712kbC++14896b2023-12-29 03:26:022023-12-29 03:26:03

Judging History

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

  • [2023-12-29 03:26:03]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3712kb
  • [2023-12-29 03:26:02]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define f first
#define s second

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
  int tt = 1;
  //cin >> tt;
  while (tt--) {
		int n;
		cin >> n;
		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];
		const int k = 30;
		int ans = 1e18;
		for (int i = 0;i < k;i++) {
			int l = 0, r = 1e18;
			for (int j = 0;j < n;j++) {
				l = max(l, b[j] * (1ll << i) - a[j]);
				r = min(r, b[j] * (1ll << i) + (1ll << i) - 1 - a[j]);
			}
			if (l == 0) {
				ans = 0;
				break;
			}
			while (l <= r) {
				int y = (l >> i);
				int x = __builtin_popcount(l & ((1 << i) - 1));
				ans = min(ans, y + x + i);
				l += (l & -l);
			}
		}
		if (ans == 1e18)
			ans = -1;
		cout << ans;
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3500kb

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

input:

3
2 3 4
1 2 3

output:

0

result:

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