結果

問題 No.397 NO MORE KADOMATSU
ユーザー ぴろずぴろず
提出日時 2016-07-15 22:38:11
言語 Java21
(openjdk 21)
結果
AC  
実行時間 190 ms / 2,000 ms
コード長 814 bytes
コンパイル時間 2,418 ms
コンパイル使用メモリ 77,160 KB
実行使用メモリ 73,080 KB
平均クエリ数 36.83
最終ジャッジ日時 2023-09-24 00:13:12
合計ジャッジ時間 6,347 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 165 ms
72,660 KB
testcase_01 AC 170 ms
72,444 KB
testcase_02 AC 137 ms
72,184 KB
testcase_03 AC 183 ms
72,524 KB
testcase_04 AC 162 ms
72,296 KB
testcase_05 AC 178 ms
70,936 KB
testcase_06 AC 172 ms
72,136 KB
testcase_07 AC 184 ms
72,776 KB
testcase_08 AC 164 ms
73,048 KB
testcase_09 AC 141 ms
71,980 KB
testcase_10 AC 182 ms
72,400 KB
testcase_11 AC 140 ms
71,840 KB
testcase_12 AC 189 ms
73,080 KB
testcase_13 AC 190 ms
72,772 KB
testcase_14 AC 189 ms
72,560 KB
testcase_15 AC 184 ms
72,692 KB
testcase_16 AC 141 ms
72,324 KB
testcase_17 AC 143 ms
72,084 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package no397;

import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i=0;i<n;i++) {
			a[i] = sc.nextInt();
		}
		ArrayList<Query> al = new ArrayList<>();
		for(int i=0;i<n;i++) {
			int min = 10000;
			int minj = -1;
			for(int j=i;j<n;j++) {
				if (a[j] < min) {
					min = a[j];
					minj = j;
				}
			}
			if (i != minj) {
				int temp = a[i];
				a[i] = a[minj];
				a[minj] = temp;
				al.add(new Query(i,minj));
			}
		}
		System.out.println(al.size());
		for(Query q:al) {
			System.out.println(q.i + " " + q.j);
		}
		sc.nextInt();
	}
	

}

class Query {
	int i,j;

	public Query(int i, int j) {
		super();
		this.i = i;
		this.j = j;
	}
	
}
0