結果

問題 No.397 NO MORE KADOMATSU
ユーザー atkrymatkrym
提出日時 2016-11-04 11:28:51
言語 Java21
(openjdk 21)
結果
AC  
実行時間 378 ms / 2,000 ms
コード長 837 bytes
コンパイル時間 2,399 ms
コンパイル使用メモリ 78,472 KB
実行使用メモリ 75,064 KB
平均クエリ数 936.56
最終ジャッジ日時 2023-09-24 00:41:02
合計ジャッジ時間 7,944 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 182 ms
72,484 KB
testcase_01 AC 176 ms
73,060 KB
testcase_02 AC 153 ms
71,772 KB
testcase_03 AC 216 ms
75,064 KB
testcase_04 AC 187 ms
72,832 KB
testcase_05 AC 220 ms
73,184 KB
testcase_06 AC 254 ms
73,300 KB
testcase_07 AC 265 ms
72,864 KB
testcase_08 AC 195 ms
72,608 KB
testcase_09 AC 164 ms
71,964 KB
testcase_10 AC 378 ms
73,760 KB
testcase_11 AC 157 ms
71,232 KB
testcase_12 AC 284 ms
72,476 KB
testcase_13 AC 315 ms
72,920 KB
testcase_14 AC 316 ms
73,240 KB
testcase_15 AC 319 ms
73,264 KB
testcase_16 AC 151 ms
72,244 KB
testcase_17 AC 150 ms
71,612 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    private static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) throws Exception {
        int n = sc.nextInt();
        int[] ary = new int[n];
        for (int i = 0;i < n;i++) {
            ary[i] = sc.nextInt();
        }
        
        List<String> list = new ArrayList<>();
        
        for (int i = n-1;i >= 0;i--) {
            for (int j = 0;j < i;j++) {
                int a = ary[j];
                int b = ary[j+1];
                if (a > b) {
                    ary[j] = b;
                    ary[j+1] = a;
                    list.add(j+" "+(j+1));
                }
            }
        }
        
        System.out.println(list.size());
        list.stream().forEach(s -> System.out.println(s));
        
        sc.next();
    }
}
0