結果
問題 |
No.693 square1001 and Permutation 2
|
ユーザー |
![]() |
提出日時 | 2018-07-17 21:22:14 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 998 bytes |
コンパイル時間 | 1,080 ms |
コンパイル使用メモリ | 99,828 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-27 07:55:38 |
合計ジャッジ時間 | 1,552 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 9 |
ソースコード
#include <stdio.h> #include <algorithm> #include <iostream> #include <string> #include <vector> #include <functional> #include <map> #include <iomanip> #include <math.h> #include <stack> #include <queue> #include <bitset> #include <cstdlib> #include <tuple> #include <cctype> using namespace std; int main() { int i, j, k; bool flag[50] = { false }; bool flag2[50] = { false }; vector<int>a(50, 9999); vector<int>b(50, 9999); int n; cin >> n; for (i = 0; i < n; i++) { cin >> a[i]; } sort(a.begin(), a.end()); for (i = 1; i <= n; i++) { for (j = 0; j < n; j++) { if (a[j] == i) { flag[j] = true; flag2[i-1] = true; break; } } } int cnt = 0; for (i = 0; i < n; i++) { if (flag[i] == false) { b[cnt] = a[i]; cnt++; } } sort(b.begin(), b.end() ); int cnt2 = 0, sum = 0; for (i = 0; i < n; i++) { if (flag2[i] == false) { sum += abs( b[cnt2] - (i+1)); cnt2++; } } cout << sum << endl; getchar(); getchar(); return 0; }