結果

問題 No.397 NO MORE KADOMATSU
ユーザー YamaKasaYamaKasa
提出日時 2018-09-19 16:44:09
言語 Java21
(openjdk 21)
結果
AC  
実行時間 390 ms / 2,000 ms
コード長 926 bytes
コンパイル時間 3,216 ms
コンパイル使用メモリ 75,880 KB
実行使用メモリ 75,308 KB
平均クエリ数 936.56
最終ジャッジ日時 2023-09-24 01:55:33
合計ジャッジ時間 8,100 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 168 ms
72,924 KB
testcase_01 AC 160 ms
72,984 KB
testcase_02 AC 139 ms
71,800 KB
testcase_03 AC 193 ms
73,256 KB
testcase_04 AC 178 ms
72,664 KB
testcase_05 AC 215 ms
72,968 KB
testcase_06 AC 249 ms
73,160 KB
testcase_07 AC 246 ms
73,000 KB
testcase_08 AC 185 ms
72,956 KB
testcase_09 AC 145 ms
72,036 KB
testcase_10 AC 390 ms
75,308 KB
testcase_11 AC 148 ms
71,432 KB
testcase_12 AC 271 ms
72,412 KB
testcase_13 AC 314 ms
73,660 KB
testcase_14 AC 320 ms
73,664 KB
testcase_15 AC 316 ms
72,812 KB
testcase_16 AC 141 ms
72,208 KB
testcase_17 AC 139 ms
71,192 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
	static List<Integer> list;
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int[]A = new int[N];
		for(int i = 0; i < N; i++) {
			A[i] = scan.nextInt();
		}
		list = new ArrayList<Integer>();
		bubbleSort(A, N);
		System.out.println(list.size() / 2);
		for(int i = 0; i < list.size(); i += 2) {
			System.out.println(list.get(i) + " " + list.get(i + 1));
		}
		System.exit(0);
		int Dummy = scan.nextInt();
		scan.close();
		if(Dummy == -1) {
			System.exit(0);
		}
	}
	static void bubbleSort(int[]A, int n) {
		boolean flag = true;
		while(flag) {
			flag = false;
			for(int i = n - 1; i >= 1; i--) {
				if(A[i] < A[i - 1]) {
					int t = A[i];
					A[i] = A[i - 1];
					A[i - 1] = t;
					flag = true;
					list.add(i);
					list.add(i-1);
				}
			}
		}
	}
}
0