結果

問題 No.693 square1001 and Permutation 2
ユーザー 37zigen37zigen
提出日時 2018-05-24 15:54:46
言語 Java19
(openjdk 21)
結果
AC  
実行時間 134 ms / 2,000 ms
コード長 725 bytes
コンパイル時間 2,147 ms
コンパイル使用メモリ 72,636 KB
実行使用メモリ 56,652 KB
最終ジャッジ日時 2023-09-11 02:57:30
合計ジャッジ時間 4,436 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
56,108 KB
testcase_01 AC 128 ms
55,884 KB
testcase_02 AC 128 ms
55,892 KB
testcase_03 AC 134 ms
56,652 KB
testcase_04 AC 134 ms
55,788 KB
testcase_05 AC 129 ms
55,848 KB
testcase_06 AC 128 ms
55,844 KB
testcase_07 AC 129 ms
56,036 KB
testcase_08 AC 130 ms
55,828 KB
testcase_09 AC 124 ms
55,824 KB
testcase_10 AC 126 ms
55,684 KB
権限があれば一括ダウンロードができます

ソースコード

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