結果

問題 No.429 CupShuffle
ユーザー Tsukasa_TypeTsukasa_Type
提出日時 2018-03-06 15:22:24
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,020 ms / 2,000 ms
コード長 1,023 bytes
コンパイル時間 2,563 ms
コンパイル使用メモリ 80,092 KB
実行使用メモリ 72,452 KB
最終ジャッジ日時 2023-10-19 03:46:23
合計ジャッジ時間 10,420 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 232 ms
61,556 KB
testcase_01 AC 161 ms
58,424 KB
testcase_02 AC 166 ms
58,600 KB
testcase_03 AC 165 ms
58,368 KB
testcase_04 AC 239 ms
60,588 KB
testcase_05 AC 163 ms
58,540 KB
testcase_06 AC 239 ms
61,728 KB
testcase_07 AC 237 ms
60,860 KB
testcase_08 AC 178 ms
58,288 KB
testcase_09 AC 240 ms
61,296 KB
testcase_10 AC 421 ms
62,612 KB
testcase_11 AC 998 ms
68,260 KB
testcase_12 AC 959 ms
67,024 KB
testcase_13 AC 1,020 ms
66,572 KB
testcase_14 AC 996 ms
72,452 KB
testcase_15 AC 159 ms
58,616 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import static java.lang.System.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int n = sc.nextInt();
		int k = sc.nextInt();
		int x = sc.nextInt();
		int[] a = new int[k];
		int[] b = new int[k];
		String temp1,temp2;
		for (int i=0; i<k; i++) {
			if (i==x-1) {temp1=sc.next(); temp2=sc.next();}
			else {
				a[i] = sc.nextInt()-1;
				b[i] = sc.nextInt()-1;
			}
		}
		int[] end = new int[n];
		for (int i=0; i<n; i++) {
			end[i] = sc.nextInt();
		}
		int[] start = new int[n];
		for (int i=0; i<n; i++) {
			start[i] = i+1;
		}
		int temp;
		for (int i=0; i<x-1; i++) {
			temp = start[a[i]];
			start[a[i]] = start[b[i]];
			start[b[i]] = temp;
			
		}
		for (int i=k-1; i>=x; i--) {
			temp = end[a[i]];
			end[a[i]] = end[b[i]];
			end[b[i]] = temp;
			
		}
		
		List<Integer> list = new ArrayList<>();
		for (int i=0; i<n; i++) {
			if (start[i]!=end[i]) {list.add(i+1);}
		}
		
		out.println(list.get(0)+" "+list.get(1));
	}
}
0