結果

問題 No.326 あみだますたー
ユーザー Daigo HIROOKADaigo HIROOKA
提出日時 2018-06-26 02:37:45
言語 Java21
(openjdk 21)
結果
AC  
実行時間 371 ms / 2,000 ms
コード長 969 bytes
コンパイル時間 3,638 ms
コンパイル使用メモリ 76,204 KB
実行使用メモリ 62,092 KB
最終ジャッジ日時 2023-09-13 14:05:19
合計ジャッジ時間 12,598 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
56,000 KB
testcase_01 AC 154 ms
56,792 KB
testcase_02 AC 207 ms
57,332 KB
testcase_03 AC 350 ms
59,772 KB
testcase_04 AC 235 ms
57,156 KB
testcase_05 AC 132 ms
55,716 KB
testcase_06 AC 300 ms
61,992 KB
testcase_07 AC 200 ms
58,456 KB
testcase_08 AC 272 ms
57,148 KB
testcase_09 AC 368 ms
62,092 KB
testcase_10 AC 371 ms
61,496 KB
testcase_11 AC 181 ms
56,948 KB
testcase_12 AC 317 ms
61,404 KB
testcase_13 AC 313 ms
61,544 KB
testcase_14 AC 254 ms
61,012 KB
testcase_15 AC 279 ms
61,588 KB
testcase_16 AC 266 ms
61,440 KB
testcase_17 AC 293 ms
61,220 KB
testcase_18 AC 281 ms
60,344 KB
testcase_19 AC 294 ms
61,732 KB
testcase_20 AC 153 ms
56,760 KB
testcase_21 AC 157 ms
56,392 KB
testcase_22 AC 312 ms
61,248 KB
testcase_23 AC 310 ms
61,448 KB
testcase_24 AC 350 ms
61,784 KB
testcase_25 AC 328 ms
61,956 KB
testcase_26 AC 243 ms
59,976 KB
testcase_27 AC 316 ms
61,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class No326{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int K = sc.nextInt();
		int[] A_tmp = new int[N];
		for(int i = 0; i < N; i++){
			A_tmp[i] = i+1;
		}
		for(int i = 0; i < K; i++){
			int x = sc.nextInt()-1;
			int y = sc.nextInt()-1;
			int tmp = A_tmp[x];
			A_tmp[x] = A_tmp[y];
			A_tmp[y] = tmp;
		}

		int[] A = new int[N];
		for(int i = 0; i < N; i++){
			A[i] = sc.nextInt();
		}
		for(int i = 0; i < N; i++){
			A_tmp[i] = A[A_tmp[i]-1];
		}

		// System.out.println(Arrays.toString(A_tmp));
		ArrayList<Integer> ans = new ArrayList<Integer>();
		for(int i = 1; i < N; i++){
			for(int j = i-1; j >= 0; j--){
				if(A_tmp[j] > A_tmp[j+1]){
					int tmp = A_tmp[j];
					A_tmp[j] = A_tmp[j+1];
					A_tmp[j+1] = tmp;
					ans.add(j);
				}
			}
		}
		
		System.out.println(ans.size());
		for(int idx:ans){
			System.out.println((idx+1) +" "+ (idx+2));
		}
	}
}
0