結果

問題 No.326 あみだますたー
ユーザー uafr_csuafr_cs
提出日時 2016-02-02 21:49:40
言語 Java21
(openjdk 21)
結果
AC  
実行時間 339 ms / 2,000 ms
コード長 1,484 bytes
コンパイル時間 3,005 ms
コンパイル使用メモリ 82,360 KB
実行使用メモリ 48,496 KB
最終ジャッジ日時 2024-04-25 12:03:27
合計ジャッジ時間 10,162 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 107 ms
40,308 KB
testcase_01 AC 138 ms
42,248 KB
testcase_02 AC 189 ms
42,292 KB
testcase_03 AC 335 ms
48,012 KB
testcase_04 AC 211 ms
43,312 KB
testcase_05 AC 122 ms
41,276 KB
testcase_06 AC 272 ms
48,248 KB
testcase_07 AC 173 ms
43,692 KB
testcase_08 AC 243 ms
43,536 KB
testcase_09 AC 339 ms
48,396 KB
testcase_10 AC 333 ms
48,412 KB
testcase_11 AC 162 ms
42,708 KB
testcase_12 AC 297 ms
47,816 KB
testcase_13 AC 306 ms
48,496 KB
testcase_14 AC 235 ms
45,380 KB
testcase_15 AC 248 ms
47,476 KB
testcase_16 AC 247 ms
48,156 KB
testcase_17 AC 263 ms
44,816 KB
testcase_18 AC 267 ms
47,236 KB
testcase_19 AC 275 ms
47,500 KB
testcase_20 AC 125 ms
42,224 KB
testcase_21 AC 143 ms
42,320 KB
testcase_22 AC 303 ms
48,344 KB
testcase_23 AC 297 ms
47,580 KB
testcase_24 AC 315 ms
48,256 KB
testcase_25 AC 304 ms
47,112 KB
testcase_26 AC 211 ms
44,732 KB
testcase_27 AC 291 ms
47,860 KB
権限があれば一括ダウンロードができます

ソースコード

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