結果

問題 No.693 square1001 and Permutation 2
ユーザー tsunabittsunabit
提出日時 2019-06-23 12:09:28
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 473 bytes
コンパイル時間 3,763 ms
コンパイル使用メモリ 72,540 KB
実行使用メモリ 57,872 KB
最終ジャッジ日時 2023-08-27 03:23:25
合計ジャッジ時間 5,694 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
55,816 KB
testcase_01 AC 126 ms
56,156 KB
testcase_02 AC 126 ms
56,432 KB
testcase_03 AC 133 ms
55,944 KB
testcase_04 AC 142 ms
56,008 KB
testcase_05 AC 126 ms
55,824 KB
testcase_06 AC 127 ms
55,868 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 130 ms
55,556 KB
testcase_10 AC 126 ms
55,864 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 = 1; i < n; i++) {
    		if(a[i] != i + 1) {
    			c += Math.abs(i + 1 - a[i]);
    		}
    	}
    	System.out.println(c);
    }
}
0