結果

問題 No.326 あみだますたー
ユーザー kou6839kou6839
提出日時 2015-12-19 22:04:58
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,170 bytes
コンパイル時間 2,362 ms
コンパイル使用メモリ 80,020 KB
実行使用メモリ 63,248 KB
最終ジャッジ日時 2023-10-17 12:54:40
合計ジャッジ時間 13,353 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 137 ms
57,484 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 142 ms
57,504 KB
testcase_06 AC 281 ms
62,704 KB
testcase_07 AC 211 ms
60,016 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
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 #

import java.net.NetworkInterface;
import java.util.*;

public class Main {
	static long gcd(long a,long b){
		return b == 0 ? a : gcd(b, a%b);
	}
	static long lcm(long a, long b){
		return a*b/gcd(a, b);
	}
	static int[] dx = {1,0,-1,0};
	static int[] dy = {0,1,0,-1};
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] moto = new int[n+1];
		int[] ch1 = new int[m];
		int[] ch2 = new int[m];
		for(int i=0;i<m;i++){
			ch1[i] = sc.nextInt();
			ch2[i] = sc.nextInt();
		}
		int[] goal = new int[n+1];
		for(int i=1;i<=n;i++){
			goal[i] = sc.nextInt();
			moto[i] = goal[i];
		}
		for(int i=0;i<m;i++){
			int tmp=moto[ch1[i]];
			moto[ch1[i]]=moto[ch2[i]];
			moto[ch2[i]]=tmp;
		}
		int ans = 0;
		StringBuilder sb = new StringBuilder();
		for(int i=1;i<n;i++){
			if(moto[i]==goal[i]){
				continue;
			}
			int b = 0;
			for(int j=1;j<=n;j++)if(moto[j]==goal[i]) b = j;
			for(int j=b;j>i;j--){
				int tmp = moto[j];
				moto[j]=moto[j-1];
				moto[j-1]=tmp;
				ans++;
				sb.append(j-1+" "+(j)+"\n");
			}
		}
		System.out.println(ans);
		System.out.println(sb);
	} 
}
0