Submission #38845915
Source Code Expand
#ifdef ONPC
#define _GLIBCXX_DEBUG
#else
#pragma GCC optimize("O3")
#pragma unroll
#endif
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
bool det(ll n, ll k) {
ll pw = (1LL << 60);
while (n > 0) {
while (pw > n) {
pw >>= 1;
}
n -= pw;
if (k >= pw) {
k -= pw;
}
if (n < k) {
return false;
}
}
return true;
}
ll Get(ll n, ll k) {
if (n % 2 == 0) {
if (det(n / 2 - 1, (k - 1) / 2)) {
return ((k - 1) ^ 1) + 1;
} else {
return k;
}
} else {
if (k > 1) {
k = Get(n - 1, k - 1) + 1;
}
if (k < n) {
k = Get(n - 1, k);
}
return k;
}
}
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout.tie(nullptr);
#ifdef ONPC
freopen("../input.txt", "r", stdin);
#endif
int q;
cin >> q;
while (q--) {
ll n, k;
cin >> n >> k;
cout << Get(n, k) << "\n";
}
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | A - Long Shuffle |
| User | Paliukh |
| Language | C++ (GCC 9.2.1) |
| Score | 500 |
| Code Size | 1184 Byte |
| Status | AC |
| Exec Time | 8 ms |
| Memory | 3524 KiB |
Compile Error
./Main.cpp:5: warning: ignoring #pragma unroll [-Wunknown-pragmas]
5 | #pragma unroll
|
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 500 / 500 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 01.txt |
| All | 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 01.txt | AC | 1 ms | 3472 KiB |
| 02.txt | AC | 2 ms | 3392 KiB |
| 03.txt | AC | 2 ms | 3480 KiB |
| 04.txt | AC | 2 ms | 3436 KiB |
| 05.txt | AC | 4 ms | 3456 KiB |
| 06.txt | AC | 8 ms | 3480 KiB |
| 07.txt | AC | 3 ms | 3444 KiB |
| 08.txt | AC | 5 ms | 3524 KiB |
| 09.txt | AC | 3 ms | 3520 KiB |
| 10.txt | AC | 4 ms | 3424 KiB |
| 11.txt | AC | 3 ms | 3480 KiB |