QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#303602#6510. Best Carry Player 3lucas110550WA 0ms3616kbC++141.1kb2024-01-12 19:55:562024-01-12 19:55:57

Judging History

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

  • [2024-01-12 19:55:57]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3616kb
  • [2024-01-12 19:55:56]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

long long x, y, k;
int T;

int main( ) {
	scanf("%d", &T);
	while (T --) {
		scanf("%lld %lld %lld", &x, &y, &k);
		if (k == 0)
			printf("%lld\n", abs(x - y));
		else {
			if (x > y)
				swap(x, y);
			int cur = -1;
			for (int i = 60; i >= 0; i --)
				if (((x >> i) & 1) != ((y >> i) & 1)) {
					cur = i;
					break;
				}
			if (cur == -1)
				printf("0\n");
			else {
				long long o = 1;
				int p = 0;
				long long K = k;
				while (K)
					K >>= 1, o <<= 1, ++ p;
				if (cur <= p) {
					long long z = x ^ y;
					if (z <= k)
						printf("1\n");
					else
						printf("2\n");
				} else {
					long long A = (y >> p);
					long long B = ((x >> p) + 1);
					long long tmp = 1, res = o - 1 - x % o;
					if (res) {
						if (res <= k)
							++ tmp;
						else
							tmp += 2;
					}
					tmp = min(tmp, (B << p) - x) + (A - B) * (2 + (k != o - 1));
					res = y % o;
					if (res == 0)
						printf("%lld\n", tmp);
					else if (res <= k)
						printf("%lld\n", tmp + 1);
					else
						printf("%lld\n", tmp + 2);
				}
			}
		}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3616kb

input:

8
4 5 0
5 8 3
9 2 6
15 28 5
97 47 8
164 275 38
114514 1919 810
0 1152921504606846975 1

output:

1
2
2
5
11
6
331
1152921504606846975

result:

wrong answer 3rd numbers differ - expected: '3', found: '2'