結果

問題 No.429 CupShuffle
ユーザー crazybbb3crazybbb3
提出日時 2016-10-29 14:37:04
言語 Java21
(openjdk 21)
結果
AC  
実行時間 351 ms / 2,000 ms
コード長 4,030 bytes
コンパイル時間 4,918 ms
コンパイル使用メモリ 83,180 KB
実行使用メモリ 62,256 KB
最終ジャッジ日時 2023-08-16 06:42:33
合計ジャッジ時間 9,108 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 106 ms
51,004 KB
testcase_01 AC 86 ms
52,824 KB
testcase_02 AC 86 ms
53,060 KB
testcase_03 AC 86 ms
52,732 KB
testcase_04 AC 98 ms
53,068 KB
testcase_05 AC 82 ms
53,936 KB
testcase_06 AC 112 ms
53,152 KB
testcase_07 AC 102 ms
53,352 KB
testcase_08 AC 91 ms
51,728 KB
testcase_09 AC 103 ms
53,412 KB
testcase_10 AC 192 ms
58,748 KB
testcase_11 AC 351 ms
61,772 KB
testcase_12 AC 349 ms
62,236 KB
testcase_13 AC 346 ms
62,256 KB
testcase_14 AC 346 ms
61,824 KB
testcase_15 AC 90 ms
52,712 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
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 = ni();
        int[] a = new int[k];
        int[] b = new int[k];
        for (int i = 0; i < k; i++) {
            if (i != x - 1) {
                a[i] = ni() - 1;
                b[i] = ni() - 1;
            } else {
                in.readLine();
            }
        }
        int[] c = nia(n);

        int[] d = new int[n];
        for (int i = 0; i < n; i++) {
            d[i] = i + 1;
        }

        for (int i = 0; i < x - 1; i++) {
            int tmp = d[a[i]];
            d[a[i]] = d[b[i]];
            d[b[i]] = tmp;
        }
        for (int i = k - 1; i >= x; i--) {
            int tmp = c[a[i]];
            c[a[i]] = c[b[i]];
            c[b[i]] = tmp;
        }

        ArrayList<Integer> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            if (c[i] != d[i]) {
                list.add(i + 1);
            }
        }

        Collections.sort(list);
        out.println(list.get(0) + " " + list.get(1));
    }

    void output(int x, int y) {
        String ans = "";
        if (x < 0) {
            for (int i = 0; i < y; i++) {
                if (i == 0) ans += "w";
                else ans += "wC";
            }
            for (int i = 0; i < x; i++) {
                ans += "cW";
            }
        } else if (y < 0) {
            for (int i = 0; i < x; i++) {
                if (i == 0) ans += "c";
                else ans += "cC";
            }
            for (int i = 0; i < x; i++) {
                ans += "wW";
            }
        } else {
            for (int i = 0; i < y; i++) {
                if (i == 0) ans += "c";
                else ans += "cC";
            }
            for (int i = 0; i < x; i++) {
                if ("".equals(ans)) ans += "w";
                ans += "wC";
            }
        }
        out.println(ans);
    }

    int gcd(int a, int b) {
        return a == 0 ? b : gcd(b % a, a);
    }

    int lcm(int a, int b) {
        return a / gcd(a, b) * b;
    }

    int[] extgcd(int a, int b, int[] is) {
        if (a == 0) {
            is[0] = 0;
            is[1] = 1;
            is[2] = b;
        } else {
            extgcd(b % a, a, is);
            int x = is[1] - b / a * is[0];
            is[1] = is[0];
            is[0] = x;
        }
        return is;
    }

    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