結果

問題 No.326 あみだますたー
ユーザー htensaihtensai
提出日時 2020-01-29 11:35:46
言語 Java21
(openjdk 21)
結果
AC  
実行時間 126 ms / 2,000 ms
コード長 1,458 bytes
コンパイル時間 2,665 ms
コンパイル使用メモリ 74,284 KB
実行使用メモリ 55,228 KB
最終ジャッジ日時 2023-10-14 05:30:55
合計ジャッジ時間 7,070 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
49,264 KB
testcase_01 AC 42 ms
49,168 KB
testcase_02 AC 48 ms
49,172 KB
testcase_03 AC 124 ms
55,228 KB
testcase_04 AC 54 ms
49,288 KB
testcase_05 AC 44 ms
49,412 KB
testcase_06 AC 106 ms
52,960 KB
testcase_07 AC 63 ms
50,672 KB
testcase_08 AC 72 ms
51,032 KB
testcase_09 AC 125 ms
53,300 KB
testcase_10 AC 126 ms
53,432 KB
testcase_11 AC 45 ms
49,152 KB
testcase_12 AC 95 ms
52,276 KB
testcase_13 AC 116 ms
53,684 KB
testcase_14 AC 56 ms
49,364 KB
testcase_15 AC 78 ms
52,448 KB
testcase_16 AC 111 ms
53,664 KB
testcase_17 AC 78 ms
50,572 KB
testcase_18 AC 77 ms
51,176 KB
testcase_19 AC 106 ms
52,336 KB
testcase_20 AC 44 ms
49,344 KB
testcase_21 AC 44 ms
49,252 KB
testcase_22 AC 97 ms
52,632 KB
testcase_23 AC 97 ms
52,428 KB
testcase_24 AC 124 ms
52,952 KB
testcase_25 AC 113 ms
53,472 KB
testcase_26 AC 60 ms
50,240 KB
testcase_27 AC 118 ms
51,096 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int kk = Integer.parseInt(br.readLine());
        int[] current = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            current[i] = i;
        }
        for (int i = 0; i < kk; i++) {
            String[] line = br.readLine().split(" ", 2);
            int a = Integer.parseInt(line[0]);
            int tmp = current[a];
            current[a] = current[a + 1];
            current[a + 1] = tmp;
        }
        int[] goal = new int[n + 1];
        String[] last = br.readLine().split(" ", n);
        for (int i = 1; i <= n; i++) {
            goal[Integer.parseInt(last[i - 1])] = i;
        }
        int count = 0;
        StringBuilder sb = new StringBuilder();
        for (int i = 1; i < n; i++) {
            int right = i;
            while (current[right] != goal[i]) {
                right++;
            }
            for (int j = right; j - 1 >= i; j--) {
                count++;
                int tmp = current[j - 1];
                current[j - 1] = current[j];
                current[j] = tmp;
                sb.append(j - 1).append(" ").append(j).append("\n");
            }
        }
        System.out.println(count);
        System.out.print(sb);
    }
}
0