結果

問題 No.429 CupShuffle
ユーザー fjafjafja
提出日時 2017-09-10 22:17:51
言語 Java
(openjdk 23)
結果
AC  
実行時間 1,020 ms / 2,000 ms
コード長 1,020 bytes
コンパイル時間 3,835 ms
コンパイル使用メモリ 79,232 KB
実行使用メモリ 59,596 KB
最終ジャッジ日時 2024-11-07 12:52:43
合計ジャッジ時間 11,987 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

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