結果
問題 | No.693 square1001 and Permutation 2 |
ユーザー |
|
提出日時 | 2018-06-08 22:26:54 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 142 ms / 2,000 ms |
コード長 | 821 bytes |
コンパイル時間 | 3,602 ms |
コンパイル使用メモリ | 77,052 KB |
実行使用メモリ | 54,428 KB |
最終ジャッジ日時 | 2024-06-30 10:47:53 |
合計ジャッジ時間 | 5,937 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 9 |
ソースコード
import java.io.*; import java.util.*; public class Main_yukicoder693 { private static Scanner sc; private static Printer pr; private static void solve() { int n = sc.nextInt(); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = sc.nextInt(); } Arrays.sort(a); int ans = 0; for (int i = 0; i < n; i++) { ans += Math.abs(i + 1 - a[i]); } pr.println(ans); } // --------------------------------------------------- public static void main(String[] args) { sc = new Scanner(INPUT == null ? System.in : new ByteArrayInputStream(INPUT.getBytes())); pr = new Printer(System.out); solve(); // pr.close(); pr.flush(); // sc.close(); } static String INPUT = null; private static class Printer extends PrintWriter { Printer(OutputStream out) { super(out); } } }