結果

問題 No.397 NO MORE KADOMATSU
ユーザー Mcpu3Mcpu3
提出日時 2018-09-19 16:14:15
言語 Java21
(openjdk 21)
結果
AC  
実行時間 408 ms / 2,000 ms
コード長 1,119 bytes
コンパイル時間 4,730 ms
コンパイル使用メモリ 75,456 KB
実行使用メモリ 73,372 KB
平均クエリ数 936.56
最終ジャッジ日時 2023-09-24 01:55:24
合計ジャッジ時間 7,908 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 170 ms
72,824 KB
testcase_01 AC 156 ms
72,088 KB
testcase_02 AC 140 ms
71,300 KB
testcase_03 AC 209 ms
72,924 KB
testcase_04 AC 171 ms
72,980 KB
testcase_05 AC 208 ms
72,800 KB
testcase_06 AC 245 ms
73,212 KB
testcase_07 AC 248 ms
73,204 KB
testcase_08 AC 174 ms
72,440 KB
testcase_09 AC 146 ms
71,592 KB
testcase_10 AC 408 ms
72,788 KB
testcase_11 AC 149 ms
71,668 KB
testcase_12 AC 284 ms
72,944 KB
testcase_13 AC 306 ms
73,372 KB
testcase_14 AC 306 ms
72,808 KB
testcase_15 AC 306 ms
72,444 KB
testcase_16 AC 144 ms
71,652 KB
testcase_17 AC 142 ms
72,364 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

class Main{
    public static int b1(int n,int a[]){
        int s=0;
        for(int i=0;i<n-1;++i){
            for(int j=n-1;j>i;--j){
                if(a[j-1]>a[j]){
                    int t=a[j-1];
                    a[j-1]=a[j];
                    a[j]=t;
                    ++s;
                }
            }
        }
        return s;
    }

    public static void b2(int n,int a[]){
        for(int i=0;i<n-1;++i){
            for(int j=n-1;j>i;--j){
                if(a[j-1]>a[j]){
                    int t=a[j-1];
                    a[j-1]=a[j];
                    a[j]=t;
                    System.out.println(j-1+" "+j);
                }
            }
        }
    }

    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt(),a[][]=new int[2][n];
        for(int i=0;i<n;++i){
            a[0][i]=sc.nextInt();
            a[1][i]=a[0][i];
        }
        sc.close();
        System.out.println(b1(n,a[0]));
        b2(n,a[1]);
        System.out.flush();
    }
}
0