結果

問題 No.326 あみだますたー
ユーザー crazybbb3crazybbb3
提出日時 2016-11-28 22:06:38
言語 Java21
(openjdk 21)
結果
AC  
実行時間 221 ms / 2,000 ms
コード長 2,594 bytes
コンパイル時間 3,605 ms
コンパイル使用メモリ 78,196 KB
実行使用メモリ 60,020 KB
最終ジャッジ日時 2023-08-18 08:55:18
合計ジャッジ時間 9,367 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
49,124 KB
testcase_01 AC 86 ms
52,700 KB
testcase_02 AC 113 ms
52,748 KB
testcase_03 AC 211 ms
60,020 KB
testcase_04 AC 121 ms
54,204 KB
testcase_05 AC 46 ms
47,168 KB
testcase_06 AC 189 ms
58,088 KB
testcase_07 AC 79 ms
50,556 KB
testcase_08 AC 163 ms
54,448 KB
testcase_09 AC 221 ms
57,956 KB
testcase_10 AC 219 ms
54,640 KB
testcase_11 AC 85 ms
52,716 KB
testcase_12 AC 163 ms
54,268 KB
testcase_13 AC 203 ms
58,332 KB
testcase_14 AC 127 ms
53,256 KB
testcase_15 AC 154 ms
54,560 KB
testcase_16 AC 181 ms
57,920 KB
testcase_17 AC 133 ms
53,060 KB
testcase_18 AC 137 ms
53,364 KB
testcase_19 AC 187 ms
57,308 KB
testcase_20 AC 83 ms
52,552 KB
testcase_21 AC 85 ms
52,708 KB
testcase_22 AC 175 ms
54,552 KB
testcase_23 AC 167 ms
54,224 KB
testcase_24 AC 209 ms
57,640 KB
testcase_25 AC 209 ms
58,700 KB
testcase_26 AC 113 ms
53,200 KB
testcase_27 AC 198 ms
54,480 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class Main {

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    void solve() throws IOException {
        int n = ni();
        int k = ni();
        int[] x = new int[k];
        int[] y = new int[k];
        for (int i = 0; i < k; i++) {
            x[i] = ni() - 1;
            y[i] = ni() - 1;
        }
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = ni() - 1;
        }

        for (int i = 0; i < k; i++) {
            int tmp = a[x[i]];
            a[x[i]] = a[y[i]];
            a[y[i]] = tmp;
        }

        ArrayList<Integer> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n - i; j++) {
                if (j + 1 < n && a[j] > a[j + 1]) {
                    list.add(j + 1);
                    int tmp = a[j];
                    a[j] = a[j + 1];
                    a[j + 1] = tmp;
                }
            }
        }

        out.println(list.size());
        for (int i = 0; i < list.size(); i++) {
            out.println(list.get(i) + " " + (list.get(i) + 1));
        }
    }

    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }

    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }

    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}
0