結果
問題 |
No.693 square1001 and Permutation 2
|
ユーザー |
![]() |
提出日時 | 2023-08-19 17:44:22 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 45 ms / 2,000 ms |
コード長 | 844 bytes |
コンパイル時間 | 1,031 ms |
コンパイル使用メモリ | 95,136 KB |
最終ジャッジ日時 | 2025-02-16 11:40:10 |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 9 |
ソースコード
#include<iostream> #include<map> #include<vector> #include <algorithm> #include<math.h> using namespace std; int main() { int n, cnt = 0; cin >> n; vector<int> v(n, 0); for (int i = 0; i < n; i++){ int t; cin >> t; v[t-1]++; } for (int i = 0; i < n; i++){ if (v[i] > 1){ int j = i + 1; while (v[i] != 1){ if (v[j] == 0){ cnt += (j - i); v[i]--; v[j]++; } else j++; } } else if (!v[i]){ for (int j = i; j < n; j++){ if (v[j] > 1){ cnt += (j - i); v[j]--; v[i]++; break; } } } } cout << cnt << endl; }