結果

問題 No.326 あみだますたー
コンテスト
ユーザー FF256grhy
提出日時 2015-12-25 04:18:00
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 699 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 263 ms
コンパイル使用メモリ 39,680 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-05-08 06:46:17
合計ジャッジ時間 1,689 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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