結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 138 ms
54,532 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 153 ms
54,372 KB
testcase_06 AC 328 ms
59,604 KB
testcase_07 AC 227 ms
56,684 KB
testcase_08 AC 299 ms
58,212 KB
testcase_09 AC 411 ms
60,072 KB
testcase_10 AC 400 ms
60,292 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