結果

問題 No.693 square1001 and Permutation 2
ユーザー 37zigen37zigen
提出日時 2018-05-24 15:54:46
言語 Java
(openjdk 23)
結果
AC  
実行時間 124 ms / 2,000 ms
コード長 725 bytes
コンパイル時間 1,789 ms
コンパイル使用メモリ 76,336 KB
実行使用メモリ 41,572 KB
最終ジャッジ日時 2024-06-28 17:29:29
合計ジャッジ時間 3,846 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

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];
		for (int i = 0; i < N; ++i) {
			A[i] = sc.nextInt();
		}
		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));
	}
}
0