結果

問題 No.429 CupShuffle
ユーザー kohaku_kohakukohaku_kohaku
提出日時 2016-11-16 14:20:53
言語 Java21
(openjdk 21)
結果
AC  
実行時間 957 ms / 2,000 ms
コード長 1,311 bytes
コンパイル時間 2,149 ms
コンパイル使用メモリ 76,164 KB
実行使用メモリ 69,788 KB
最終ジャッジ日時 2023-08-17 07:24:54
合計ジャッジ時間 9,513 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 222 ms
60,124 KB
testcase_01 AC 150 ms
56,804 KB
testcase_02 AC 154 ms
56,736 KB
testcase_03 AC 155 ms
57,016 KB
testcase_04 AC 216 ms
60,128 KB
testcase_05 AC 147 ms
56,576 KB
testcase_06 AC 222 ms
61,964 KB
testcase_07 AC 218 ms
60,356 KB
testcase_08 AC 157 ms
56,724 KB
testcase_09 AC 208 ms
58,096 KB
testcase_10 AC 422 ms
61,084 KB
testcase_11 AC 957 ms
68,944 KB
testcase_12 AC 907 ms
67,000 KB
testcase_13 AC 951 ms
69,788 KB
testcase_14 AC 943 ms
69,016 KB
testcase_15 AC 152 ms
56,744 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int [] Cupf = new int [N];
        for(int i=0; i<N; i++){
            Cupf[i]=i+1;
        }
        int K = sc.nextInt();
        int [] A = new int [K];
        int [] B = new int [K];
        int X = sc.nextInt();
        for(int i=0; i<K; i++){
            if(i!=X-1){
                A[i]=sc.nextInt();
                B[i]=sc.nextInt();
            }else{
                String x=sc.next();
                String y=sc.next();
            }
        }
        
        for(int i=0; i<X-1; i++){
            int t = Cupf[ A[i]-1 ];
            Cupf[ A[i]-1 ] = Cupf[ B[i]-1 ];
            Cupf[ B[i]-1 ] = t;
        }
        

        int [] Cupt = new int [N];
        for(int i=0; i<N; i++){
            Cupt[i]=sc.nextInt();
        }
        for(int i=K-1; i>X-1; i--){
            int t = Cupt[ A[i]-1 ];
            Cupt[ A[i]-1 ] = Cupt[ B[i]-1 ];
            Cupt[ B[i]-1 ] = t;
        }
        int [] r = new int [2];
        int z =0;
        for(int i=0; i<N; i++){
            if(Cupf[i]!=Cupt[i]){
                r[z]=i+1;
                z++;
            }
        }
        System.out.println(r[0]+" "+r[1]);
    }
}
0