結果

問題 No.326 あみだますたー
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2016-04-23 22:41:24
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 687 bytes
コンパイル時間 1,250 ms
コンパイル使用メモリ 164,952 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 04:21:09
合計ジャッジ時間 4,413 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 4 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 8 ms
6,940 KB
testcase_09 AC 9 ms
6,940 KB
testcase_10 AC 9 ms
6,944 KB
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 <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)

typedef vector<int> vi;
typedef pair<int, int> pii;

int main()
{
	int N, K; cin >> N >> K;

	vi B(N);
	rep(i, 0, N) B[i] = i;

	while (0 < K--)
	{
		int x, y; cin >> x >> y;
		x--; y--;
		swap(B[x], B[y]);
	}

	vi A(N);
	rep(i, 0, N) cin >> A[i];
	rep(i, 0, N) A[i]--;

	vector<pii> ans;
	rep(i, 0, N)
	{
		int index = 0;
		rep(j, i, N) if (A[i] == B[j]) index = j;
		rrep(j, index, i + 1)
		{
			ans.push_back(pii(j-1, j));
			swap(B[j-1], B[j]);
		}
	}

	cout << ans.size() << endl;
	for (pii p : ans) cout << (p.first+1) << " " << (p.second+1) << endl;
}
0