結果

問題 No.693 square1001 and Permutation 2
ユーザー tsunabittsunabit
提出日時 2019-06-23 12:12:10
言語 Java21
(openjdk 21)
結果
AC  
実行時間 132 ms / 2,000 ms
コード長 473 bytes
コンパイル時間 3,283 ms
コンパイル使用メモリ 72,320 KB
実行使用メモリ 56,424 KB
最終ジャッジ日時 2023-08-27 03:23:31
合計ジャッジ時間 5,487 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
54,004 KB
testcase_01 AC 128 ms
55,840 KB
testcase_02 AC 128 ms
55,644 KB
testcase_03 AC 132 ms
56,068 KB
testcase_04 AC 129 ms
56,112 KB
testcase_05 AC 125 ms
55,768 KB
testcase_06 AC 125 ms
56,208 KB
testcase_07 AC 123 ms
56,424 KB
testcase_08 AC 127 ms
56,012 KB
testcase_09 AC 127 ms
56,116 KB
testcase_10 AC 126 ms
56,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class No693 {
    public static void main(String[] args) {
    	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 c = 0;
    	for(int i = 0; i < n; i++) {
    		if(a[i] != i + 1) {
    			c += Math.abs(i + 1 - a[i]);
    		}
    	}
    	System.out.println(c);
    }
}
0