Submission #38847947
Source Code Expand
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const double PI = acos(-1);
int main() {
int t;
cin >> t;
rep(ti,t) {
ll n, k;
cin >> n >> k;
ll ans = 0;
if (n%8 == 2) {
if (k <= 2 || k >= n-1) {
if (k%2 == 1) ans = k+1;
else ans = k-1;
} else {
ans = k;
}
} else if (n%8 == 3) {
if (k == 1) ans = k+1;
else if (k == 2) ans = k+1;
else if (k == 3) ans = k-2;
else if (k == n) ans = n-2;
else if (k == n-1) ans = n;
else if (k == n-2) ans = n-1;
else ans = k;
} else if (n%8 == 4) {
if (k <= 4 || k >= n-3) {
if (k%2 == 1) ans = k+1;
else ans = k-1;
} else {
ans = k;
}
} else if (n%8 == 5) {
if (k <= 5 || k >= n-4) {
if (k%8 == 1) ans = k+1;
else if (k%8 == 2) ans = k+2;
else if (k%8 == 3) ans = k-2;
else if (k%8 == 4) ans = k+1;
else ans = k-2;
} else {
ans = k;
}
} else if (n%8 == 6) {
if (k <= 6 || k >= n-5) {
if (k%4 == 1) ans = k+1;
else if (k%4 == 2) ans = k-1;
else ans = k;
} else {
ans = k;
}
} else if (n%8 == 7) {
if (k <= 7 || k >= n-6) {
if (k%4 == 1) ans = k+1;
else if (k%4 == 2) ans = k+1;
else if (k%4 == 3) ans = k-2;
else ans = k;
} else {
ans = k;
}
} else if (n%8 == 0) {
if (k%2 == 1) ans = k+1;
else ans = k-1;
} else {
if (k <= 9 || k >= n-8) {
if (k == 1) ans = k+1;
else if (k == n-1) ans = k+1;
else if (k%2 == 1) ans = k-2;
else ans = k+2;
} else {
ans = k;
}
}
cout << ans << endl;
}
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | A - Long Shuffle |
| User | taki0711 |
| Language | C++ (GCC 9.2.1) |
| Score | 0 |
| Code Size | 2630 Byte |
| Status | WA |
| Exec Time | 12 ms |
| Memory | 3616 KiB |
Judge Result
| Set Name | Sample | All | ||||||
|---|---|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 0 / 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 | 8 ms | 3616 KiB |
| 02.txt | AC | 2 ms | 3412 KiB |
| 03.txt | WA | 9 ms | 3612 KiB |
| 04.txt | WA | 7 ms | 3428 KiB |
| 05.txt | WA | 8 ms | 3400 KiB |
| 06.txt | WA | 7 ms | 3468 KiB |
| 07.txt | AC | 12 ms | 3488 KiB |
| 08.txt | WA | 7 ms | 3544 KiB |
| 09.txt | WA | 8 ms | 3608 KiB |
| 10.txt | WA | 10 ms | 3472 KiB |
| 11.txt | WA | 8 ms | 3424 KiB |