結果

問題 No.326 あみだますたー
ユーザー 37zigen37zigen
提出日時 2016-05-02 20:55:07
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,235 bytes
コンパイル時間 2,464 ms
コンパイル使用メモリ 83,904 KB
実行使用メモリ 60,716 KB
最終ジャッジ日時 2024-04-15 09:20:55
合計ジャッジ時間 14,172 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 141 ms
54,352 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 151 ms
54,268 KB
testcase_06 AC 321 ms
59,888 KB
testcase_07 AC 220 ms
56,692 KB
testcase_08 AC 303 ms
58,100 KB
testcase_09 AC 396 ms
59,776 KB
testcase_10 AC 401 ms
60,080 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Queue;
import java.util.Scanner;
public class Main{
	public static void main(String[] args)throws Exception{
		new Main().solve();
	}
	void solve(){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int k=sc.nextInt();

		int[] d=new int[n];
		for(int i=0;i<n;i++){
			d[i]=i;
		}
		for(int i=0;i<k;i++){
			int x=sc.nextInt()-1;
			int y=sc.nextInt()-1;
			d=Arrays.copyOf(swap(d,x,y), d.length);
		}
		Queue<Pair> q=new ArrayDeque<Pair>();
		for(int i=0;i<n;i++){
			int a=sc.nextInt()-1;
			if(d[i]==a)continue;
			for(int j=0;j<n;j++){
				if(d[j]==a){
					a=j;
					break;
				}
			}
			for(int j=a;j>i;j--){
				d=Arrays.copyOf(swap(d,j,j-1), d.length);
				q.add(new Pair(j-1,j));
			}
		}
		System.out.println(q.size());
		while(!q.isEmpty()){
			Pair p=q.poll();
			System.out.println((p.a+1)+" "+(p.b+1));
		}
	}
	class Pair{
		//a<bとする
		int a;
		int b;
		Pair(int a,int b){
			if(a>b){
				int d=a;
				a=b;
				b=d;
			}
			this.a=a;
			this.b=b;
		}
	}
	int[] swap(int[] d,int a,int b){
		int dumy=d[a];
		d[a]=d[b];
		d[b]=dumy;
		return d;
	}
	void tr(Object...o){System.out.println(Arrays.deepToString(o));}
}
0