結果

問題 No.326 あみだますたー
ユーザー Daigo HIROOKADaigo HIROOKA
提出日時 2018-06-26 04:48:54
言語 Java21
(openjdk 21)
結果
MLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,169 bytes
コンパイル時間 3,875 ms
コンパイル使用メモリ 77,380 KB
実行使用メモリ 64,160 KB
最終ジャッジ日時 2023-09-13 14:06:06
合計ジャッジ時間 12,540 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
55,704 KB
testcase_01 AC 154 ms
56,796 KB
testcase_02 AC 200 ms
57,244 KB
testcase_03 MLE -
testcase_04 AC 232 ms
56,844 KB
testcase_05 AC 131 ms
55,992 KB
testcase_06 MLE -
testcase_07 AC 197 ms
58,500 KB
testcase_08 AC 276 ms
57,416 KB
testcase_09 AC 386 ms
60,980 KB
testcase_10 AC 351 ms
62,036 KB
testcase_11 AC 172 ms
56,788 KB
testcase_12 AC 319 ms
61,340 KB
testcase_13 AC 320 ms
61,660 KB
testcase_14 AC 246 ms
61,264 KB
testcase_15 AC 269 ms
61,596 KB
testcase_16 AC 280 ms
61,384 KB
testcase_17 AC 306 ms
60,444 KB
testcase_18 AC 287 ms
60,536 KB
testcase_19 AC 299 ms
61,724 KB
testcase_20 AC 153 ms
56,940 KB
testcase_21 AC 154 ms
56,732 KB
testcase_22 AC 317 ms
61,996 KB
testcase_23 AC 315 ms
62,120 KB
testcase_24 AC 341 ms
61,728 KB
testcase_25 AC 323 ms
61,508 KB
testcase_26 AC 217 ms
61,028 KB
testcase_27 AC 315 ms
61,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

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

		int N = sc.nextInt();
		int K = sc.nextInt();
		ArrayList<Integer> A_tmp = new ArrayList<Integer>(N);
		for(int i = 0; i < N; i++){
			A_tmp.add(i+1);
		}
		for(int i = 0; i < K; i++){
			int x = sc.nextInt()-1;
			int y = sc.nextInt()-1;
			int tmp = A_tmp.get(x);
			A_tmp.set(x, A_tmp.get(y));
			A_tmp.set(y, tmp);
		}

		
		ArrayList<Integer> A_end = new ArrayList<Integer>(N);
		for(int i = 0; i < N; i++) A_end.add(0);
		for(int i = 0; i < N; i++){
			int idx_end = sc.nextInt()-1;
			A_end.set(idx_end, i+1);
		}

		// System.out.println(A_tmp.toString());
		// System.out.println(A_end.toString());
				ArrayList<Integer> ans = new ArrayList<Integer>(N*N/2);
		for(int i = 0; i < N; i++){
			if(A_tmp.get(i) != A_end.get(i)){
				int a_end = A_end.get(i);
				int idx = A_tmp.indexOf(a_end);
				for(int j = idx-1; j >= i; j--){
					A_tmp.set(j+1, A_tmp.get(j));
					ans.add(j);
				}
				A_tmp.set(i, a_end);
			}
		}

		System.out.println(ans.size());
		for(int idx:ans){
			System.out.println((idx+1) +" "+ (idx+2));
		}
	}
}
0