結果

問題 No.397 NO MORE KADOMATSU
ユーザー nCk_cvnCk_cv
提出日時 2016-08-28 19:44:52
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 937 bytes
コンパイル時間 2,482 ms
コンパイル使用メモリ 79,008 KB
実行使用メモリ 73,724 KB
平均クエリ数 188.61
最終ジャッジ日時 2023-09-23 11:22:52
合計ジャッジ時間 8,807 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 187 ms
72,840 KB
testcase_01 AC 181 ms
73,188 KB
testcase_02 AC 152 ms
71,908 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 AC 154 ms
73,724 KB
testcase_10 RE -
testcase_11 AC 155 ms
71,872 KB
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 AC 144 ms
71,584 KB
testcase_17 AC 146 ms
72,072 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main {
		static int INF = 2 << 27;
		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();
			}
			List<Integer> u = new ArrayList<>();
			List<Integer> v = new ArrayList<>();
			for(int i = 1; i < N; i++) {
				for(int j = i-1; j >= 0; j--) {
					if(A[j] <= A[i] || j == 0) {
						if(j+1 == i) break;
						int tmp = A[j+1];
						A[j+1] = A[i];
						A[i] = tmp;
						u.add(j+1);
						v.add(i);
					}
				}
			}
			System.out.println(u.size());
			for(int i = 0; i < u.size(); i++) {
				System.out.println(u.get(i) + " " + v.get(i));
			}
			sc.nextInt();
		}
		static boolean isSorted(int[] A) {
			for(int i = 0; i < A.length-1; i++) {
				if(A[i] > A[i+1]) return false;
			}
			return true;
		}
		

}
0