結果

問題 No.693 square1001 and Permutation 2
ユーザー htensaihtensai
提出日時 2019-11-12 07:39:01
言語 Java21
(openjdk 21)
結果
AC  
実行時間 141 ms / 2,000 ms
コード長 404 bytes
コンパイル時間 2,162 ms
コンパイル使用メモリ 74,468 KB
実行使用メモリ 57,624 KB
最終ジャッジ日時 2023-10-17 11:33:32
合計ジャッジ時間 4,670 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 132 ms
57,436 KB
testcase_01 AC 121 ms
56,328 KB
testcase_02 AC 134 ms
57,528 KB
testcase_03 AC 137 ms
57,604 KB
testcase_04 AC 141 ms
57,580 KB
testcase_05 AC 131 ms
57,468 KB
testcase_06 AC 131 ms
57,496 KB
testcase_07 AC 133 ms
57,592 KB
testcase_08 AC 132 ms
57,588 KB
testcase_09 AC 132 ms
57,624 KB
testcase_10 AC 133 ms
57,564 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) throws Exception {
		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 total = 0;
		for (int i = 1; i <= n; i++) {
		    total += Math.abs(arr[i - 1] - i);
		}
		System.out.println(total);
	}
}
0