結果

問題 No.326 あみだますたー
ユーザー TatsuDXTatsuDX
提出日時 2016-10-16 21:38:30
言語 Java21
(openjdk 21)
結果
AC  
実行時間 382 ms / 2,000 ms
コード長 958 bytes
コンパイル時間 3,866 ms
コンパイル使用メモリ 78,740 KB
実行使用メモリ 48,524 KB
最終ジャッジ日時 2024-05-02 02:36:29
合計ジャッジ時間 13,382 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 143 ms
41,204 KB
testcase_01 AC 171 ms
42,128 KB
testcase_02 AC 219 ms
42,604 KB
testcase_03 AC 375 ms
48,084 KB
testcase_04 AC 253 ms
43,116 KB
testcase_05 AC 148 ms
41,496 KB
testcase_06 AC 307 ms
48,056 KB
testcase_07 AC 219 ms
43,900 KB
testcase_08 AC 288 ms
43,592 KB
testcase_09 AC 382 ms
48,460 KB
testcase_10 AC 375 ms
48,524 KB
testcase_11 AC 181 ms
42,360 KB
testcase_12 AC 339 ms
48,104 KB
testcase_13 AC 334 ms
48,452 KB
testcase_14 AC 261 ms
43,360 KB
testcase_15 AC 281 ms
47,080 KB
testcase_16 AC 289 ms
47,792 KB
testcase_17 AC 309 ms
45,420 KB
testcase_18 AC 296 ms
46,048 KB
testcase_19 AC 309 ms
48,084 KB
testcase_20 AC 170 ms
42,360 KB
testcase_21 AC 165 ms
42,148 KB
testcase_22 AC 335 ms
47,940 KB
testcase_23 AC 340 ms
47,600 KB
testcase_24 AC 356 ms
48,456 KB
testcase_25 AC 345 ms
48,260 KB
testcase_26 AC 249 ms
44,660 KB
testcase_27 AC 337 ms
48,396 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Test {
	public static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int n = sc.nextInt(), k = sc.nextInt(), a, b, tmp, cnt = 0;
		String[] s = new String[n * (n - 1) / 2];
		int[] t = new int[n + 1], m = new int[n + 1];
		for (int i = 1; i <= n; i++) {
			t[i] = i;
		}
		for (int i = 0; i < k; i++) {
			a = sc.nextInt();
			b = sc.nextInt();
			tmp = t[a];
			t[a] = t[b];
			t[b] = tmp;
		}
		for (int i = 1; i <= n; i++) {
			tmp = sc.nextInt();
			m[tmp] = i;
		}
		for (int i = 1; i < n; i++) {
			if (t[i] == m[i]) {
				continue;
			}
			for (int j = i + 1; j <= n; j++) {
				if (t[j] == m[i]) {
					for (int l = j; l > i; l--) {
						tmp = t[l - 1];
						t[l - 1] = t[l];
						t[l] = tmp;
						s[cnt] = (l - 1) + " " + l;
						cnt++;
					}
					break;
				}
			}
		}
		System.out.println(cnt);
		for (int i = 0; i < cnt; i++) {
			System.out.println(s[i]);
		}
	}
}
0