結果

問題 No.326 あみだますたー
ユーザー kou6839kou6839
提出日時 2015-12-19 22:11:25
言語 Java21
(openjdk 21)
結果
MLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,164 bytes
コンパイル時間 3,364 ms
コンパイル使用メモリ 76,640 KB
実行使用メモリ 64,084 KB
最終ジャッジ日時 2023-08-07 18:27:41
合計ジャッジ時間 11,277 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
55,640 KB
testcase_01 AC 151 ms
56,564 KB
testcase_02 AC 170 ms
56,812 KB
testcase_03 AC 286 ms
61,472 KB
testcase_04 AC 173 ms
56,780 KB
testcase_05 AC 130 ms
56,004 KB
testcase_06 AC 265 ms
61,228 KB
testcase_07 AC 191 ms
57,956 KB
testcase_08 AC 201 ms
57,392 KB
testcase_09 MLE -
testcase_10 AC 283 ms
61,620 KB
testcase_11 AC 160 ms
56,836 KB
testcase_12 AC 257 ms
60,060 KB
testcase_13 AC 281 ms
61,468 KB
testcase_14 AC 224 ms
61,056 KB
testcase_15 AC 251 ms
60,840 KB
testcase_16 AC 268 ms
61,504 KB
testcase_17 AC 238 ms
60,280 KB
testcase_18 AC 239 ms
60,568 KB
testcase_19 AC 264 ms
61,256 KB
testcase_20 AC 151 ms
56,780 KB
testcase_21 AC 150 ms
56,304 KB
testcase_22 AC 266 ms
61,556 KB
testcase_23 AC 256 ms
60,368 KB
testcase_24 AC 284 ms
61,956 KB
testcase_25 AC 277 ms
61,752 KB
testcase_26 AC 227 ms
60,160 KB
testcase_27 AC 270 ms
61,120 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