結果

問題 No.693 square1001 and Permutation 2
ユーザー tentententen
提出日時 2020-10-09 09:21:55
言語 Java21
(openjdk 21)
結果
AC  
実行時間 132 ms / 2,000 ms
コード長 456 bytes
コンパイル時間 1,996 ms
コンパイル使用メモリ 71,324 KB
実行使用メモリ 56,192 KB
最終ジャッジ日時 2023-09-27 12:35:11
合計ジャッジ時間 4,702 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
55,416 KB
testcase_01 AC 126 ms
55,940 KB
testcase_02 AC 126 ms
55,620 KB
testcase_03 AC 132 ms
55,856 KB
testcase_04 AC 132 ms
55,916 KB
testcase_05 AC 125 ms
55,924 KB
testcase_06 AC 124 ms
55,796 KB
testcase_07 AC 124 ms
55,660 KB
testcase_08 AC 126 ms
55,796 KB
testcase_09 AC 127 ms
56,180 KB
testcase_10 AC 125 ms
56,192 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[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }
        Arrays.sort(arr);
        int ans = 0;
        for (int i = 0; i < n; i++) {
            ans += Math.abs(i + 1 - arr[i]);
        }
        System.out.println(ans);
    }
}
0