結果

問題 No.1604 Swap Sort:ONE
ユーザー tentententen
提出日時 2022-09-29 11:44:27
言語 Java21
(openjdk 21)
結果
AC  
実行時間 93 ms / 2,000 ms
コード長 1,546 bytes
コンパイル時間 2,080 ms
コンパイル使用メモリ 74,056 KB
実行使用メモリ 52,216 KB
最終ジャッジ日時 2023-08-24 04:56:41
合計ジャッジ時間 6,086 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,100 KB
testcase_01 AC 44 ms
49,272 KB
testcase_02 AC 43 ms
49,396 KB
testcase_03 AC 44 ms
49,172 KB
testcase_04 AC 43 ms
49,248 KB
testcase_05 AC 76 ms
51,304 KB
testcase_06 AC 93 ms
51,852 KB
testcase_07 AC 87 ms
52,216 KB
testcase_08 AC 87 ms
51,376 KB
testcase_09 AC 83 ms
51,516 KB
testcase_10 AC 83 ms
51,736 KB
testcase_11 AC 81 ms
51,756 KB
testcase_12 AC 82 ms
51,748 KB
testcase_13 AC 82 ms
51,692 KB
testcase_14 AC 84 ms
51,136 KB
testcase_15 AC 83 ms
51,868 KB
testcase_16 AC 82 ms
51,608 KB
testcase_17 AC 75 ms
51,616 KB
testcase_18 AC 75 ms
51,336 KB
testcase_19 AC 82 ms
51,992 KB
testcase_20 AC 76 ms
51,384 KB
testcase_21 AC 81 ms
51,352 KB
testcase_22 AC 77 ms
51,240 KB
testcase_23 AC 58 ms
50,276 KB
testcase_24 AC 52 ms
49,228 KB
testcase_25 AC 81 ms
51,928 KB
testcase_26 AC 82 ms
51,560 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int[] place = new int[n + 1];
        int[] values = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            values[i] = sc.nextInt();
            place[values[i]] = i;
        }
        int count = 0;
        for (int i = 1; i <= n; i++) {
            while (values[i] > i) {
                int current = values[i];
                place[current] = place[current - 1];
                values[place[current - 1]] = current;
                values[i] = current - 1;
                place[current - 1] = i;
                count++;
            }
        }
        System.out.println(count);
    }
}
    
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0