結果

問題 No.397 NO MORE KADOMATSU
ユーザー uwiuwi
提出日時 2016-07-15 22:28:32
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 1,445 bytes
コンパイル時間 6,456 ms
コンパイル使用メモリ 80,628 KB
実行使用メモリ 75,008 KB
平均クエリ数 39.11
最終ジャッジ日時 2023-09-23 11:02:43
合計ジャッジ時間 9,895 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 173 ms
72,444 KB
testcase_01 RE -
testcase_02 AC 142 ms
71,780 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 AC 148 ms
72,204 KB
testcase_10 AC 174 ms
72,744 KB
testcase_11 AC 148 ms
71,720 KB
testcase_12 AC 177 ms
72,264 KB
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 AC 135 ms
69,644 KB
testcase_17 AC 149 ms
71,904 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package contest;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Q1233 {
	static Scanner in;
	static PrintWriter out;
	static String INPUT = "";
	
	static void solve()
	{
		int n = ni();
		int[] a = new int[n];
		for(int i = 0;i < n;i++){
			a[i] = ni();
		}
		int[][] ai = new int[n][];
		for(int i = 0;i < n;i++){
			ai[i] = new int[]{a[i], i};
		}
		Arrays.sort(ai, new Comparator<int[]>() {
			public int compare(int[] a, int[] b) {
				return a[0] - b[0];
			}
		});
		
		List<String> list = new ArrayList<>();
		for(int i = 0;i < n;i++){
			if(ai[i][1] != i){
				for(int j = i;j < n;j++){
					if(ai[j][1] == i){
						list.add(i + " " + j);
						int[] d = ai[i]; ai[i] = ai[j]; ai[j] = d;
						break;
					}
				}
			}
		}
		out.println(list.size());
		for(String line : list){
			out.println(line);
		}
		out.flush();
		ni();
	}
	
	public static void main(String[] args) throws Exception
	{
		in = INPUT.isEmpty() ? new Scanner(System.in) : new Scanner(INPUT);
		out = new PrintWriter(System.out);
		
		solve();
		out.flush();
	}
	
	static int ni() { return Integer.parseInt(in.next()); }
	static long nl() { return Long.parseLong(in.next()); }
	static double nd() { return Double.parseDouble(in.next()); }
	static void tr(Object... o) { if(INPUT.length() != 0)System.out.println(Arrays.deepToString(o)); }
}
0