結果

問題 No.326 あみだますたー
ユーザー tentententen
提出日時 2020-11-18 18:08:06
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,350 bytes
コンパイル時間 2,261 ms
コンパイル使用メモリ 77,056 KB
実行使用メモリ 61,216 KB
最終ジャッジ日時 2023-09-30 15:08:44
合計ジャッジ時間 11,512 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
55,392 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 129 ms
55,448 KB
testcase_06 AC 225 ms
58,956 KB
testcase_07 AC 196 ms
58,776 KB
testcase_08 AC 168 ms
56,152 KB
testcase_09 AC 248 ms
60,096 KB
testcase_10 AC 238 ms
59,256 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = i;
        }
        for (int i = 0; i < k; i++) {
            int idx = sc.nextInt();
            sc.nextInt();
            int tmp = arr[idx];
            arr[idx] = arr[idx - 1];
            arr[idx - 1] = tmp;
        }
        int[] next = new int[n];
        for (int i = 0; i < n; i++) {
            next[i] = sc.nextInt() - 1;
        }
        ArrayList<Integer> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            int idx = 0;
            for (int j = i; j < n; j++) {
                if (arr[j] == next[i]) {
                    idx = j;
                    break;
                }
            }
            for (int j = idx; j > i; j--) {
                int tmp = arr[j];
                arr[j] = arr[j - 1];
                arr[j - 1] = tmp;
                list.add(j);
            }
        }
        StringBuilder sb = new StringBuilder();
        sb.append(list.size()).append("\n");
        for (int x : list) {
            sb.append(x).append(" ").append(x + 1).append("\n");
        }
        System.out.print(sb);
    }
}
0