結果

問題 No.693 square1001 and Permutation 2
ユーザー GrenacheGrenache
提出日時 2018-06-08 22:26:54
言語 Java21
(openjdk 21)
結果
AC  
実行時間 127 ms / 2,000 ms
コード長 821 bytes
コンパイル時間 3,899 ms
コンパイル使用メモリ 73,648 KB
実行使用メモリ 56,576 KB
最終ジャッジ日時 2023-09-12 23:54:47
合計ジャッジ時間 5,696 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 114 ms
56,264 KB
testcase_01 AC 117 ms
56,084 KB
testcase_02 AC 118 ms
56,576 KB
testcase_03 AC 127 ms
56,284 KB
testcase_04 AC 121 ms
56,316 KB
testcase_05 AC 117 ms
56,056 KB
testcase_06 AC 123 ms
56,156 KB
testcase_07 AC 113 ms
55,700 KB
testcase_08 AC 115 ms
54,104 KB
testcase_09 AC 117 ms
56,096 KB
testcase_10 AC 111 ms
55,868 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;


public class Main_yukicoder693 {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		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(i + 1 - a[i]);
		}

		pr.println(ans);
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(INPUT == null ? System.in : new ByteArrayInputStream(INPUT.getBytes()));
		pr = new Printer(System.out);

		solve();

//		pr.close();
		pr.flush();
//		sc.close();
	}

	static String INPUT = null;

	private static class Printer extends PrintWriter {
		Printer(OutputStream out) {
			super(out);
		}
	}
}
0