結果

問題 No.326 あみだますたー
ユーザー ぴろずぴろず
提出日時 2015-12-20 21:26:33
言語 Java21
(openjdk 21)
結果
AC  
実行時間 344 ms / 2,000 ms
コード長 950 bytes
コンパイル時間 1,955 ms
コンパイル使用メモリ 83,964 KB
実行使用メモリ 49,172 KB
最終ジャッジ日時 2024-04-25 12:00:04
合計ジャッジ時間 9,774 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
39,928 KB
testcase_01 AC 127 ms
42,156 KB
testcase_02 AC 183 ms
42,032 KB
testcase_03 AC 321 ms
46,848 KB
testcase_04 AC 211 ms
42,956 KB
testcase_05 AC 122 ms
41,208 KB
testcase_06 AC 271 ms
47,052 KB
testcase_07 AC 178 ms
44,272 KB
testcase_08 AC 238 ms
43,724 KB
testcase_09 AC 336 ms
49,172 KB
testcase_10 AC 321 ms
47,980 KB
testcase_11 AC 147 ms
42,264 KB
testcase_12 AC 299 ms
47,780 KB
testcase_13 AC 293 ms
48,212 KB
testcase_14 AC 223 ms
44,980 KB
testcase_15 AC 241 ms
47,632 KB
testcase_16 AC 246 ms
47,964 KB
testcase_17 AC 261 ms
44,940 KB
testcase_18 AC 259 ms
46,736 KB
testcase_19 AC 274 ms
48,244 KB
testcase_20 AC 137 ms
42,396 KB
testcase_21 AC 136 ms
42,172 KB
testcase_22 AC 283 ms
47,936 KB
testcase_23 AC 344 ms
47,652 KB
testcase_24 AC 305 ms
48,312 KB
testcase_25 AC 301 ms
46,764 KB
testcase_26 AC 208 ms
45,484 KB
testcase_27 AC 287 ms
47,184 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package no326;

import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] p = new int[n];
		for(int i=0;i<n;i++) {
			p[i] = i + 1;
		}
		for(int i=0;i<k;i++) {
			int x = sc.nextInt() - 1;
			int y = sc.nextInt() - 1;
			int temp = p[x];
			p[x] = p[y];
			p[y] = temp;
		}
		int[] a = new int[n];
		for(int i=0;i<n;i++) {
			a[i] = sc.nextInt();
		}
		for(int i=0;i<n;i++) {
			p[i] = a[p[i]-1];
		}
//		System.out.println(Arrays.toString(p));
		ArrayList<Integer> ans = new ArrayList<>();
		//insertion sort
		for(int i=1;i<n;i++) {
			for(int j=i-1;j>=0;j--) {
				if (p[j] > p[j+1]) {
					int temp = p[j];
					p[j] = p[j+1];
					p[j+1] = temp;
					ans.add(j);
				}
			}
		}
		System.out.println(ans.size());
		for(int x:ans) {
			System.out.println((x + 1) + " " + (x + 2));
		}
	}

}
0