結果

問題 No.326 あみだますたー
ユーザー FF256grhyFF256grhy
提出日時 2015-12-25 04:18:00
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 699 bytes
コンパイル時間 179 ms
コンパイル使用メモリ 26,496 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-07 18:28:48
合計ジャッジ時間 1,628 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <stdio.h>

int n, k, a[100], s[100], t[100], ans[6000];

void swap(int x) {
	int temp = t[ s[x + 1] ];
	t[ s[x + 1] ] = t[ s[x] ];
	t[ s[x] ] = temp;
	temp = s[x + 1];
	s[x + 1] = s[x];
	s[x] = temp;
}

int main(void) {
	int x, y, i, j;
	scanf("%d%d", &n, &k);
	for(i = 0; i < n; i++) { s[i] = t[i] = i; }
	for(i = 0; i < k; i++) {
		scanf("%d%d", &x, &y); x--;
		swap(x);
	}
	for(i = 0; i < n; i++) {
		int temp;
		scanf("%d", &temp); a[temp - 1] = i;
	}
	
	int c = 0;
	for(i = 0; i < n; i++) {
		j = t[ a[i] ] - 1;
		while(i <= j) {
			ans[c] = j; c++;
			swap(j);
			j--;
		}
	}
	
	printf("%d\n", c);
	for(i = 0; i < c; i++) { printf("%d %d\n", ans[i] + 1, ans[i] + 2); }
	
	return 0;
}
0