提出 #38848820


ソースコード 拡げる

#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
typedef long long ll;
using namespace std;

const int maxn = 1005;
int n, a[maxn];

void solve(int l, int r) {
	if(l + 1 == r) {
		swap(a[l], a[r]);
//		cout << l << ' ';
		return;
	}
	solve(l, r - 1);
	solve(l + 1, r);
}

//const ll L = 5000;
//map<pair<ll, ll>, ll> f;
//ll solve(ll n, ll k) {
//	if(f.count(mp(n, k))) {
//		return f[mp(n, k)];
//	}
//	if(n + 1 == k) {
//		return k;
//	}
//	if(n == 2) {
//		return 3 - k;
//	}
//	if(k == 1) {
//		return f[mp(n, k)] = solve(n - 1, k);
//	}
//	return f[mp(n, k)] = solve(n - 1, solve(n - 1, k - 1) + 1);
//}
ll solve(ll n, ll k) {
	// n % 2 == 0
	ll p = (k - 1) / 2;
	if(((n / 2 - 1) & p) == p) {
		return ((k - 1) ^ 1) + 1;
	}
	return k;
}
ll calc(ll n, ll k) {
	if(n + 1 == k) {
		return k;
	}
	if(n % 2 == 0) {
		return solve(n, k);
	}
	if(k == 1) {
		return calc(n - 1, k);
	}
	return calc(n - 1, calc(n - 1, k - 1) + 1);
}
int main() {
#ifdef DEBUG
	freopen("1.in", "r", stdin);
	freopen("1.out", "w", stdout);
#endif
	ios::sync_with_stdio(0);
	cin.tie(0);
	int T;
	cin >> T;
	while(T--) {
		ll n, k;
		cin >> n >> k;
		if(n % 2 == 0) {
			cout << solve(n, k) << '\n';
			continue;
		}
		cout << calc(n, k) << '\n';
	}
//	cout << 0 << '\n';
//	for(int i = 2; i <= 20; i++) {
//		for(int j = 1; j <= i; j++) {
//			a[j] = j;
//		}
//		solve(1, i);
//		for(int j = 1; j <= i; j++) {
//			cout << a[j] - 1 << ' ';
//		}
//		cout << '\n';
//	}
//	return 0;
//	cout << 0 << '\n';
//	for(int i = 2; i <= L; i++) {
//		for(int j = 1; j <= i; j++) {
//			cout << solve(i, j) - 1 << ' ';
//		}
//		cout << '\n';
//	}
//	return 0;
//	int T;
//	cin >> T;
//	while(T--) {
//		ll n, k;
//		cin >> n >> k;
//		if(n == k) {
//			cout << n / 2 * 2 - 1 << '\n';
//			continue;
//		}
//		if(k <= L) {
//			cout << solve(min(n, L), k) << '\n';
//		}
//		else if(k > n - L) {
//			cout << n - L + solve(L, k - (n - L)) << '\n';
//		}
//		else {
//			cout << k << '\n';
//		}
//	}
	return 0;
}

提出情報

提出日時
問題 A - Long Shuffle
ユーザ yanchengzhi
言語 C++ (GCC 9.2.1)
得点 500
コード長 2174 Byte
結果 AC
実行時間 8 ms
メモリ 3660 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 500 / 500
結果
AC × 1
AC × 11
セット名 テストケース
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
ケース名 結果 実行時間 メモリ
01.txt AC 8 ms 3584 KiB
02.txt AC 2 ms 3600 KiB
03.txt AC 2 ms 3480 KiB
04.txt AC 2 ms 3524 KiB
05.txt AC 2 ms 3544 KiB
06.txt AC 4 ms 3572 KiB
07.txt AC 3 ms 3532 KiB
08.txt AC 2 ms 3588 KiB
09.txt AC 3 ms 3660 KiB
10.txt AC 3 ms 3544 KiB
11.txt AC 3 ms 3540 KiB