結果

問題 No.326 あみだますたー
ユーザー uafr_csuafr_cs
提出日時 2016-02-02 21:37:09
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,484 bytes
コンパイル時間 3,234 ms
コンパイル使用メモリ 87,760 KB
実行使用メモリ 63,612 KB
最終ジャッジ日時 2023-10-21 18:45:58
合計ジャッジ時間 14,637 ms
ジャッジサーバーID
(参考情報)
judge14 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 138 ms
57,432 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 141 ms
57,620 KB
testcase_06 AC 306 ms
62,688 KB
testcase_07 AC 208 ms
59,736 KB
testcase_08 AC 286 ms
56,976 KB
testcase_09 AC 372 ms
62,972 KB
testcase_10 AC 376 ms
63,072 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 #

import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		
		int[] current = new int[N];
		for(int i = 0; i < N; i++){ 
			current[i] = i;
		}
		
		final int K = sc.nextInt();
		for(int i = 0; i < K; i++){
			final int X = sc.nextInt() - 1;
			final int Y = sc.nextInt() - 1;
			
			{
				final int tmp = current[X];
				current[X] = current[Y];
				current[Y] = tmp;
			}
		}
		//System.out.println(Arrays.toString(current));
		
		int[] purpose = new int[N];
		for(int i = 0; i < N; i++){
			purpose[i] = sc.nextInt() - 1;
		}
		//System.out.println(Arrays.toString(purpose));
		
		
		LinkedList<String> answers = new LinkedList<String>();	
		for(int i = 0; i < N; i++){
			if(current[i] != purpose[i]){
				
				for(int index = i + 1; index < N; index++){
					if(current[index] != purpose[i]){ continue; }
					
					{
						for(int j = index - 1; j >= i; j--){
							answers.add((j + 1) + " " + (j + 2)); 
							
							int tmp = current[j + 1];
							current[j + 1] = current[j];
							current[j] = tmp;
						}
					}
					
					//System.out.println(Arrays.toString(current));
					break;
				}
				
			}
		}
		
		System.out.println(answers.size());
		for(String str : answers){
			System.out.println(str);
		}
		//System.out.println(Arrays.toString(current));
	}

}
0