結果
問題 |
No.2029 Swap Min Max Min
|
ユーザー |
|
提出日時 | 2022-08-06 00:19:49 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,011 bytes |
コンパイル時間 | 1,994 ms |
コンパイル使用メモリ | 196,436 KB |
最終ジャッジ日時 | 2025-01-30 18:54:35 |
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 WA * 1 |
other | AC * 24 WA * 18 |
ソースコード
#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; now ++; ans1 += abs(B[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; } }