結果

問題 No.693 square1001 and Permutation 2
ユーザー matsuyoshi30matsuyoshi30
提出日時 2018-06-08 23:32:34
言語 Java21
(openjdk 21)
結果
AC  
実行時間 129 ms / 2,000 ms
コード長 412 bytes
コンパイル時間 5,003 ms
コンパイル使用メモリ 71,076 KB
実行使用メモリ 56,520 KB
最終ジャッジ日時 2023-09-13 00:22:57
合計ジャッジ時間 4,129 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
55,928 KB
testcase_01 AC 122 ms
54,148 KB
testcase_02 AC 124 ms
56,400 KB
testcase_03 AC 129 ms
55,632 KB
testcase_04 AC 128 ms
56,032 KB
testcase_05 AC 124 ms
55,876 KB
testcase_06 AC 121 ms
55,868 KB
testcase_07 AC 121 ms
56,272 KB
testcase_08 AC 122 ms
56,284 KB
testcase_09 AC 122 ms
56,520 KB
testcase_10 AC 122 ms
56,296 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] a = new int[n];
        for(int i=0; i<n; i++) a[i] = in.nextInt();

        Arrays.sort(a);

        int sum = 0;
        for(int i=0; i<n; i++) {
            sum += Math.abs(a[i] - (i + 1));
        }

        System.out.println(sum);
    }
}
0