結果
問題 |
No.693 square1001 and Permutation 2
|
ユーザー |
![]() |
提出日時 | 2018-06-26 17:22:42 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 520 bytes |
コンパイル時間 | 1,739 ms |
コンパイル使用メモリ | 195,960 KB |
最終ジャッジ日時 | 2025-01-06 11:36:59 |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 9 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); ++i) int main(){ cin.tie(0); ios::sync_with_stdio(false); int n,ans = 0; cin >> n; int a[n]; rep(i,n){ cin >> a[i]; } sort(a, a+n); rep(i,n){ while(1){ if(a[i] == i + 1) break; else if (a[i] < i + 1){ a[i]++; ans++; }else{ a[i]--; ans++; } } } cout << ans << endl; return 0; }