結果

問題 No.397 NO MORE KADOMATSU
ユーザー atkrym
提出日時 2016-11-04 11:28:51
言語 Java
(openjdk 23)
結果
AC  
実行時間 406 ms / 2,000 ms
コード長 837 bytes
コンパイル時間 2,718 ms
コンパイル使用メモリ 89,744 KB
実行使用メモリ 73,096 KB
平均クエリ数 936.56
最終ジャッジ日時 2024-07-17 00:35:40
合計ジャッジ時間 8,611 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

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