結果

問題 No.326 あみだますたー
ユーザー 37zigen37zigen
提出日時 2016-05-02 21:16:25
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,227 bytes
コンパイル時間 2,914 ms
コンパイル使用メモリ 80,536 KB
実行使用メモリ 62,040 KB
最終ジャッジ日時 2024-04-15 09:23:48
合計ジャッジ時間 17,175 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 164 ms
54,416 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 178 ms
54,132 KB
testcase_06 AC 378 ms
60,060 KB
testcase_07 AC 247 ms
56,892 KB
testcase_08 AC 341 ms
58,320 KB
testcase_09 AC 469 ms
59,640 KB
testcase_10 AC 453 ms
60,148 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.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);
		}
		ArrayDeque<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=i+1;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.addLast(new Pair(j-1,j));
			}
		}
		System.out.println(q.size());
		while(!q.isEmpty()){
			Pair p=q.pollFirst();
			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