結果

問題 No.326 あみだますたー
ユーザー data9824data9824
提出日時 2015-12-19 00:38:09
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 10 ms / 2,000 ms
コード長 1,087 bytes
コンパイル時間 527 ms
コンパイル使用メモリ 67,440 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-25 11:54:29
合計ジャッジ時間 1,577 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 6 ms
5,376 KB
testcase_04 AC 5 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 8 ms
5,376 KB
testcase_09 AC 9 ms
5,376 KB
testcase_10 AC 10 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 6 ms
5,376 KB
testcase_13 AC 5 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 4 ms
5,376 KB
testcase_18 AC 3 ms
5,376 KB
testcase_19 AC 3 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 5 ms
5,376 KB
testcase_23 AC 5 ms
5,376 KB
testcase_24 AC 6 ms
5,376 KB
testcase_25 AC 5 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 5 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>

using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	vector<int> x(k);
	for (int i = 0; i < k; ++i) {
		cin >> x[i];
		--x[i];
		int y;
		cin >> y;
	}
	vector<int> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		--a[i];
	}
	vector<int> starts(n);
	for (int i = 0; i < n; ++i) {
		starts[a[i]] = i;
	}
	vector<int> goals(n);
	for (int i = 0; i < n; ++i) {
		goals[i] = i;
	}
	for (int i = 0; i < k; ++i) {
		swap(goals[x[i]], goals[x[i] + 1]);
	}
	vector<int> resultX;
	for (int i = 0; i < n - 1; ++i) {
		int middle = distance(goals.begin(), find(goals.begin(), goals.end(), starts[i]));
		vector<int> newX;
		for (int k = middle - 1; k >= i; --k) {
			newX.push_back(k);
		}
		for (size_t k = 0; k < newX.size(); ++k) {
			swap(goals[newX[k]], goals[newX[k] + 1]);
		}
		resultX.insert(resultX.end(), newX.begin(), newX.end());
	}
	cout << resultX.size() << endl;
	for (size_t i = 0; i < resultX.size(); ++i) {
		cout << (resultX[i] + 1) << " " << (resultX[i] + 2) << endl;
	}
	return 0;
}
0