結果

問題 No.397 NO MORE KADOMATSU
ユーザー YamaKasaYamaKasa
提出日時 2018-09-19 16:37:59
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 928 bytes
コンパイル時間 2,446 ms
コンパイル使用メモリ 76,120 KB
実行使用メモリ 73,560 KB
平均クエリ数 1.72
最終ジャッジ日時 2023-09-23 16:21:22
合計ジャッジ時間 9,253 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 179 ms
72,448 KB
testcase_01 WA -
testcase_02 AC 151 ms
71,180 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 160 ms
71,160 KB
testcase_10 WA -
testcase_11 AC 159 ms
71,964 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 146 ms
71,008 KB
testcase_17 AC 139 ms
71,636 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() / 2; i += 2) {
			System.out.print(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