結果

問題 No.429 CupShuffle
ユーザー fjafjafjafjafjafja
提出日時 2017-09-10 22:17:51
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,194 ms / 2,000 ms
コード長 1,020 bytes
コンパイル時間 3,744 ms
コンパイル使用メモリ 79,544 KB
実行使用メモリ 59,960 KB
最終ジャッジ日時 2024-04-25 03:13:22
合計ジャッジ時間 12,144 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 233 ms
44,940 KB
testcase_01 AC 161 ms
42,076 KB
testcase_02 AC 162 ms
42,192 KB
testcase_03 AC 165 ms
42,196 KB
testcase_04 AC 228 ms
45,204 KB
testcase_05 AC 159 ms
42,368 KB
testcase_06 AC 239 ms
45,132 KB
testcase_07 AC 234 ms
45,040 KB
testcase_08 AC 165 ms
42,168 KB
testcase_09 AC 237 ms
45,124 KB
testcase_10 AC 491 ms
48,252 KB
testcase_11 AC 995 ms
55,704 KB
testcase_12 AC 990 ms
58,160 KB
testcase_13 AC 1,099 ms
54,240 KB
testcase_14 AC 1,194 ms
59,960 KB
testcase_15 AC 164 ms
42,148 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;

import java.util.Scanner;

public class N429 {

	public static void main(String[] args)
	{
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt(),K=sc.nextInt(),X=sc.nextInt();
		int[] h=new int[N],hh=new int[N];
		int[] a=new int[K],b=new int[K];
		for(int i=0;i<N;i++)
		{
			h[i]=i+1;
		}
		for(int i=0;i<X-1;i++)
		{
			a[i]=sc.nextInt();b[i]=sc.nextInt();
		}
		String[] buf=new String[2];
		buf[0]=sc.next();buf[1]=sc.next();
	//	String buf=sc.next();
		for(int i=X;i<K;i++)
		{
			a[i]=sc.nextInt();b[i]=sc.nextInt();
		}

		for(int i=0;i<N;i++)
		{
			hh[i]=sc.nextInt();
		}

		for(int i=0;i<X-1;i++)
		{
			swap(h,a[i]-1,b[i]-1);
		}
		for(int i=K-1;i>=X;i--)
		{
			swap(hh,a[i]-1,b[i]-1);
		}

		int[] ans=new int[2];
		int p=-1;
		for(int i=0;i<N;i++)
		{
			if(h[i]!=hh[i]&&p==-1){ans[0]=i+1;p=h[i];}
			if(p==hh[i]){ans[1]=i+1;break;}
		}

		System.out.println(ans[0]+" "+ans[1]);

	}



	static void swap(int[] h,int n1,int n2)
	{
		int buf=h[n1];
		h[n1]=h[n2];
		h[n2]=buf;
	}

}
0