結果

問題 No.693 square1001 and Permutation 2
ユーザー Tsukasa_TypeTsukasa_Type
提出日時 2018-06-11 00:09:44
言語 Java21
(openjdk 21)
結果
AC  
実行時間 124 ms / 2,000 ms
コード長 1,093 bytes
コンパイル時間 1,911 ms
コンパイル使用メモリ 72,200 KB
実行使用メモリ 57,824 KB
最終ジャッジ日時 2023-09-13 02:48:45
合計ジャッジ時間 4,089 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
56,180 KB
testcase_01 AC 120 ms
56,364 KB
testcase_02 AC 114 ms
56,280 KB
testcase_03 AC 124 ms
55,964 KB
testcase_04 AC 124 ms
56,668 KB
testcase_05 AC 118 ms
55,628 KB
testcase_06 AC 115 ms
56,044 KB
testcase_07 AC 118 ms
55,936 KB
testcase_08 AC 119 ms
56,184 KB
testcase_09 AC 118 ms
57,824 KB
testcase_10 AC 119 ms
57,732 KB
権限があれば一括ダウンロードができます

ソースコード

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