結果
| 問題 | No.693 square1001 and Permutation 2 | 
| コンテスト | |
| ユーザー |  tenten | 
| 提出日時 | 2020-10-09 09:21:55 | 
| 言語 | Java (openjdk 23) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 143 ms / 2,000 ms | 
| コード長 | 456 bytes | 
| コンパイル時間 | 2,161 ms | 
| コンパイル使用メモリ | 74,236 KB | 
| 実行使用メモリ | 54,360 KB | 
| 最終ジャッジ日時 | 2024-07-20 06:42:52 | 
| 合計ジャッジ時間 | 4,803 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 9 | 
ソースコード
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);
    }
}
            
            
            
        