結果

問題 No.397 NO MORE KADOMATSU
ユーザー kohaku_kohakukohaku_kohaku
提出日時 2016-11-16 15:59:22
言語 Java21
(openjdk 21)
結果
AC  
実行時間 212 ms / 2,000 ms
コード長 955 bytes
コンパイル時間 2,736 ms
コンパイル使用メモリ 76,156 KB
実行使用メモリ 73,104 KB
平均クエリ数 51.33
最終ジャッジ日時 2023-09-24 00:42:46
合計ジャッジ時間 7,393 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 183 ms
72,844 KB
testcase_01 AC 177 ms
72,436 KB
testcase_02 AC 181 ms
72,608 KB
testcase_03 AC 198 ms
72,540 KB
testcase_04 AC 180 ms
72,360 KB
testcase_05 AC 198 ms
72,656 KB
testcase_06 AC 189 ms
70,892 KB
testcase_07 AC 198 ms
72,488 KB
testcase_08 AC 178 ms
73,104 KB
testcase_09 AC 194 ms
72,948 KB
testcase_10 AC 162 ms
72,048 KB
testcase_11 AC 192 ms
72,808 KB
testcase_12 AC 201 ms
73,076 KB
testcase_13 AC 192 ms
72,536 KB
testcase_14 AC 195 ms
73,068 KB
testcase_15 AC 212 ms
72,728 KB
testcase_16 AC 184 ms
72,520 KB
testcase_17 AC 178 ms
72,176 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    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();
        }
        int c=0;
        int [][] exchange = new int [2][N];
        for(int i=0; i<N; i++){
            int max=0;
            for(int j=i; j<N; j++){
                max=Math.max(max,A[j]);
            }
            for(int j=i+1; j<N; j++){
                if(max==A[j]){
                    A[j]=A[i];
                    A[i]=max;
                    exchange[0][c]=i;
                    exchange[1][c]=j;
                    c++;
                    break;
                }
            }
        }
        System.out.println(c);
        for(int i=0; i<c; i++){
            System.out.println(exchange[0][i]+" "+exchange[1][i]);
        }
        int Dummy = sc.nextInt();
    }
}
0