結果

問題 No.326 あみだますたー
ユーザー kou6839kou6839
提出日時 2015-12-19 22:11:25
言語 Java21
(openjdk 21)
結果
AC  
実行時間 288 ms / 2,000 ms
コード長 1,164 bytes
コンパイル時間 2,005 ms
コンパイル使用メモリ 79,420 KB
実行使用メモリ 48,532 KB
最終ジャッジ日時 2024-04-25 11:59:38
合計ジャッジ時間 8,889 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 112 ms
41,372 KB
testcase_01 AC 125 ms
42,164 KB
testcase_02 AC 141 ms
41,864 KB
testcase_03 AC 288 ms
48,080 KB
testcase_04 AC 153 ms
42,768 KB
testcase_05 AC 120 ms
41,356 KB
testcase_06 AC 248 ms
47,392 KB
testcase_07 AC 194 ms
43,832 KB
testcase_08 AC 188 ms
42,952 KB
testcase_09 AC 282 ms
48,532 KB
testcase_10 AC 265 ms
48,508 KB
testcase_11 AC 135 ms
42,560 KB
testcase_12 AC 228 ms
47,044 KB
testcase_13 AC 253 ms
47,748 KB
testcase_14 AC 197 ms
43,704 KB
testcase_15 AC 233 ms
46,776 KB
testcase_16 AC 242 ms
46,800 KB
testcase_17 AC 212 ms
44,828 KB
testcase_18 AC 221 ms
45,688 KB
testcase_19 AC 249 ms
47,228 KB
testcase_20 AC 141 ms
42,364 KB
testcase_21 AC 120 ms
41,724 KB
testcase_22 AC 246 ms
48,020 KB
testcase_23 AC 234 ms
46,448 KB
testcase_24 AC 260 ms
47,892 KB
testcase_25 AC 254 ms
46,596 KB
testcase_26 AC 199 ms
45,176 KB
testcase_27 AC 246 ms
47,076 KB
権限があれば一括ダウンロードができます

ソースコード

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[sc.nextInt()] = i;
			moto[i] = 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