結果
| 問題 |
No.693 square1001 and Permutation 2
|
| コンテスト | |
| ユーザー |
htensai
|
| 提出日時 | 2019-11-12 07:39:01 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 137 ms / 2,000 ms |
| コード長 | 404 bytes |
| コンパイル時間 | 2,251 ms |
| コンパイル使用メモリ | 75,136 KB |
| 実行使用メモリ | 41,844 KB |
| 最終ジャッジ日時 | 2024-09-17 09:49:28 |
| 合計ジャッジ時間 | 4,318 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 9 |
ソースコード
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);
}
}
htensai