結果

問題 No.326 あみだますたー
ユーザー femtofemto
提出日時 2016-08-19 02:43:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 921 bytes
コンパイル時間 848 ms
コンパイル使用メモリ 81,692 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-25 09:08:45
合計ジャッジ時間 4,925 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cassert>
using namespace std;

int A[100];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N, K;
	cin >> N >> K;
	for(int i = 0; i < N; i++) {
		A[i] = i + 1;
	}
	for(int i = 0; i < K; i++) {
		int X, Y;
		cin >> X >> Y;
		swap(A[X - 1], A[Y - 1]);
	}
	for(int i = 0; i < N; i++) {
		cin >> A[i];
	}

	vector<int> v;
	for(int i = 0; i < N; i++) {
		if(A[i] == i + 1) continue;
		for(int j = i + 1; j < N; j++) {
			if(A[j] == i + 1) {
				for(int k = j; k > i; k--) {
					v.push_back(k - 1);
					v.push_back(k);
					swap(A[k - 1], A[k]);
				}
				break;
			}
		}
		assert(A[i] == i + 1);
	}

	reverse(v.begin(), v.end());
	cout << v.size() / 2 << endl;
	for(int i = 0; i < v.size() / 2; i++) {
		cout << v[2 * i] + 1 << " " << v[2 * i + 1] + 1 << endl;;
	}
}
0