結果

問題 No.1707 Simple Range Reverse Problem
ユーザー startcppstartcpp
提出日時 2021-10-16 14:38:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,028 bytes
コンパイル時間 621 ms
コンパイル使用メモリ 72,832 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 22:11:08
合計ジャッジ時間 1,495 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 3 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 3 ms
4,348 KB
testcase_14 AC 3 ms
4,348 KB
testcase_15 AC 3 ms
4,348 KB
testcase_16 AC 3 ms
4,348 KB
testcase_17 AC 3 ms
4,348 KB
testcase_18 AC 3 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//手で試しに書いてみると、1回操作したときそれ以上操作しても意味がないことが分かる。
//証明:A・BA・B -> A・A' B'・B,  AとBに共通の数はない。
//だから初手を全探索すればいい。この性質は面白い!!
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

void reverse(vector<int> &x, int l, int r) {
	while (l < r) {
		swap(x[l], x[r]); l++; r--;
	}
}

bool check(vector<int> &x, vector<int> &a) {
	for (int i = 0; i < x.size(); i++) {
		if (x[i] != a[i]) return false;
	}
	return true;
}

int main() {
	int T, n;
	
	cin >> T;
	while (T--) {
		int n; cin >> n;
		vector<int> a(2 * n);
		for (int i = 0; i < 2 * n; i++) { cin >> a[i]; a[i]--; }
		
		vector<int> x(2 * n);
		for (int i = 0; i < 2 * n; i++) { x[i] = i % n; }
		
		int i;
		for (i = 0; i < n; i++) {
			reverse(x, i, n + i);
			if (check(x, a)) { cout << "Yes" << endl; break; }
			reverse(x, i, n + i);
		}
		if (i == n) { cout << "No" << endl; }
	}
	return 0;
}
0