結果
| 問題 |
No.693 square1001 and Permutation 2
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-05-24 15:57:29 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 136 ms / 2,000 ms |
| コード長 | 850 bytes |
| コンパイル時間 | 2,115 ms |
| コンパイル使用メモリ | 78,924 KB |
| 実行使用メモリ | 41,504 KB |
| 最終ジャッジ日時 | 2024-06-28 17:29:34 |
| 合計ジャッジ時間 | 4,232 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 9 |
ソースコード
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws FileNotFoundException {
new Main().run();
}
void run() throws FileNotFoundException {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int[] A = new int[N];
if (!(1 <= N && N <= 50))
throw new AssertionError();
for (int i = 0; i < N; ++i) {
A[i] = sc.nextInt();
if (!(1 <= A[i] && A[i] <= N))
throw new AssertionError();
}
Arrays.sort(A);
int ans = 0;
for (int i = 0; i < N; ++i) {
ans += Math.abs(A[i] - (i + 1));
}
System.out.println(ans);
}
void tr(Object... objects) {
System.out.println(Arrays.deepToString(objects));
}
}