結果

問題 No.693 square1001 and Permutation 2
ユーザー Maeda
提出日時 2025-09-08 17:02:10
言語 Java
(openjdk 23)
結果
AC  
実行時間 141 ms / 2,000 ms
コード長 608 bytes
コンパイル時間 2,729 ms
コンパイル使用メモリ 78,604 KB
実行使用メモリ 46,488 KB
最終ジャッジ日時 2025-09-08 17:02:19
合計ジャッジ時間 5,501 ms
ジャッジサーバーID
(参考情報)
judge / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        List<Integer> list = new ArrayList<Integer>();
        for(int i = 0 ; i < n ; i++){
        	list.add(scan.nextInt());
        }
        Collections.sort(list);
        int count = 0;
        for(int i = 0 ; i < n ; i++){
        	if(list.get(i) < i+1){
        		count += (i+1) - list.get(i);
        	}else if(list.get(i) > i+1){
        		count += list.get(i) - (i+1);
        	}
        }
        System.out.println(count);
    }
}
0