結果

問題 No.397 NO MORE KADOMATSU
ユーザー kohaku_kohaku
提出日時 2016-11-16 15:59:22
言語 Java
(openjdk 23)
結果
AC  
実行時間 233 ms / 2,000 ms
コード長 955 bytes
コンパイル時間 2,925 ms
コンパイル使用メモリ 87,168 KB
実行使用メモリ 73,156 KB
平均クエリ数 51.33
最終ジャッジ日時 2024-07-17 00:37:44
合計ジャッジ時間 7,469 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

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