提出 #62135288


ソースコード 拡げる

#include <bits/stdc++.h>
using namespace std;

#define PII pair<int, int>
#define _for(i, a, b) for (int i = (a); i <= (b); i++)
#define _pfor(i, a, b) for (int i = (a); i >= (b); i--)
#define int long long
const int N = 3e5 + 5;

int T, n, k, cnt, res, id;

signed main() {
	cin >> T;
	while (T--) {
		cin >> n >> k;
		cnt = 0, res = 0, id = 0;
		_for(i, 0, 32) if (n >> i & 1) id = i;
		_for(i, 0, id) cnt += (!(n >> i & 1));
		int tt = 1;
		_for(i, 1, cnt) tt = tt * 2;
		if (tt < k) {
			puts("-1");
			continue;
		}
		_pfor(i, id, 0) {
			if (!(n >> i & 1)) {
				cnt--;
				if (k > (1 << cnt)) {
					k -= (1 << cnt);
					res += (1 << i);
				}
			}
			else res += (1 << i);
		}
	  cout << res << endl;
	}
}

提出情報

提出日時
問題 B - XOR = MOD
ユーザ Kingna
言語 C++ 17 (gcc 12.2)
得点 500
コード長 750 Byte
結果 AC
実行時間 330 ms
メモリ 3672 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 500 / 500
結果
AC × 1
AC × 29
セット名 テストケース
Sample 00_sample_00.txt
All 00_sample_00.txt, 01_handmade_00.txt, 01_handmade_01.txt, 01_handmade_02.txt, 01_handmade_03.txt, 01_handmade_04.txt, 01_handmade_05.txt, 02_small_00.txt, 02_small_01.txt, 03_random_00.txt, 03_random_01.txt, 03_random_02.txt, 03_random_03.txt, 03_random_04.txt, 03_random_05.txt, 03_random_06.txt, 03_random_07.txt, 03_random_08.txt, 03_random_09.txt, 03_random_10.txt, 03_random_11.txt, 03_random_12.txt, 03_random_13.txt, 03_random_14.txt, 03_random_15.txt, 03_random_16.txt, 03_random_17.txt, 03_random_18.txt, 03_random_19.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 1 ms 3448 KiB
01_handmade_00.txt AC 30 ms 3616 KiB
01_handmade_01.txt AC 1 ms 3528 KiB
01_handmade_02.txt AC 303 ms 3532 KiB
01_handmade_03.txt AC 299 ms 3496 KiB
01_handmade_04.txt AC 319 ms 3668 KiB
01_handmade_05.txt AC 322 ms 3452 KiB
02_small_00.txt AC 262 ms 3488 KiB
02_small_01.txt AC 283 ms 3536 KiB
03_random_00.txt AC 298 ms 3516 KiB
03_random_01.txt AC 299 ms 3540 KiB
03_random_02.txt AC 300 ms 3540 KiB
03_random_03.txt AC 298 ms 3472 KiB
03_random_04.txt AC 299 ms 3672 KiB
03_random_05.txt AC 330 ms 3448 KiB
03_random_06.txt AC 329 ms 3484 KiB
03_random_07.txt AC 327 ms 3532 KiB
03_random_08.txt AC 330 ms 3532 KiB
03_random_09.txt AC 327 ms 3604 KiB
03_random_10.txt AC 295 ms 3444 KiB
03_random_11.txt AC 294 ms 3456 KiB
03_random_12.txt AC 296 ms 3480 KiB
03_random_13.txt AC 294 ms 3532 KiB
03_random_14.txt AC 294 ms 3672 KiB
03_random_15.txt AC 322 ms 3480 KiB
03_random_16.txt AC 322 ms 3532 KiB
03_random_17.txt AC 322 ms 3476 KiB
03_random_18.txt AC 321 ms 3612 KiB
03_random_19.txt AC 324 ms 3600 KiB