結果
問題 | No.693 square1001 and Permutation 2 |
ユーザー |
|
提出日時 | 2019-06-23 12:12:10 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 143 ms / 2,000 ms |
コード長 | 473 bytes |
コンパイル時間 | 3,313 ms |
コンパイル使用メモリ | 74,984 KB |
実行使用メモリ | 41,540 KB |
最終ジャッジ日時 | 2024-12-26 10:24:46 |
合計ジャッジ時間 | 5,418 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 9 |
ソースコード
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); } }