結果
| 問題 |
No.2029 Swap Min Max Min
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-08-06 00:23:45 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 84 ms / 2,000 ms |
| コード長 | 1,034 bytes |
| コンパイル時間 | 2,229 ms |
| コンパイル使用メモリ | 196,468 KB |
| 最終ジャッジ日時 | 2025-01-30 18:55:30 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 42 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main () {
int N;
cin >> N;
std::vector<ll> A(N);
for (auto& a : A) {
cin >> a;
}
cout << N / 2 << " ";
if (N % 2) {
ll ans = 0;
ll now = 1;
for (int i = 0; i < N; i ++) {
if (A[i] <= N / 2) {
ans += abs(now - i);
now += 2;
}
}
cout << ans << endl;
} else {
ll ans1 = 0;
ll now = 0;
vector<ll> B(N / 2);
for (int i = 0; i < N; i ++) {
if (A[i] <= N / 2) {
B[now] = i - now * 2;
ans1 += abs(B[now]);
now ++;
}
}
ll ans2 = 0;
now = 0;
for (int i = 0; i < N / 2; i ++) {
if (B[i] > 0) {
now --;
} else {
now ++;
}
ans2 = min(ans2, now);
}
cout << ans2 + ans1 << endl;
// return 139;
}
}