結果

問題 No.693 square1001 and Permutation 2
ユーザー Tsukasa_Type
提出日時 2018-06-11 00:09:44
言語 Java
(openjdk 23)
結果
AC  
実行時間 133 ms / 2,000 ms
コード長 1,093 bytes
コンパイル時間 2,128 ms
コンパイル使用メモリ 74,348 KB
実行使用メモリ 41,512 KB
最終ジャッジ日時 2024-06-30 13:24:36
合計ジャッジ時間 4,171 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

import static java.lang.System.*;
import java.util.*;

public class Main {
	//初期フィールド・メソッド---------------------------------------------
	static Scanner sc = new Scanner(System.in);
	static int min(int... ar) {Arrays.sort(ar); return ar[0];}
	static int max(int... ar) {Arrays.sort(ar); return ar[ar.length-1];}
	//------------------------------------------------------------


	//フィールド追加場所-----------------------------------------------
	//------------------------------------------------------------


	//メソッド追加場所------------------------------------------------
	//------------------------------------------------------------


	//mainメソッド---------------------------------------------------
	public static void main(String[] args) {
		int n = sc.nextInt();
		int[] ar = new int[n];
		for (int i=0; i<n; i++) ar[i] = sc.nextInt();
		Arrays.sort(ar);
		
		int cost = 0;
		for (int i=0; i<n; i++) {
			cost += Math.abs(ar[i]-(i+1));
		}
		
		out.println(cost);
	}
	//------------------------------------------------------------
}
0