結果

問題 No.693 square1001 and Permutation 2
ユーザー tsunabittsunabit
提出日時 2019-06-23 12:09:28
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 473 bytes
コンパイル時間 3,531 ms
コンパイル使用メモリ 75,232 KB
実行使用メモリ 41,448 KB
最終ジャッジ日時 2024-12-26 10:24:24
合計ジャッジ時間 5,404 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 7 WA * 2
権限があれば一括ダウンロードができます

ソースコード

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