結果

問題 No.2029 Swap Min Max Min
ユーザー ruthenruthen
提出日時 2022-08-05 22:57:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,005 bytes
コンパイル時間 2,237 ms
コンパイル使用メモリ 203,856 KB
実行使用メモリ 6,204 KB
最終ジャッジ日時 2023-10-14 00:34:54
合計ジャッジ時間 4,568 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 8 ms
4,356 KB
testcase_06 AC 14 ms
4,352 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 5 ms
4,352 KB
testcase_11 WA -
testcase_12 AC 10 ms
4,348 KB
testcase_13 WA -
testcase_14 AC 21 ms
4,532 KB
testcase_15 WA -
testcase_16 AC 22 ms
4,408 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 22 ms
4,380 KB
testcase_20 AC 22 ms
4,388 KB
testcase_21 AC 21 ms
4,520 KB
testcase_22 AC 21 ms
4,396 KB
testcase_23 WA -
testcase_24 AC 22 ms
5,960 KB
testcase_25 AC 19 ms
4,556 KB
testcase_26 AC 20 ms
4,512 KB
testcase_27 WA -
testcase_28 AC 1 ms
4,352 KB
testcase_29 AC 1 ms
4,356 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 WA -
testcase_33 AC 1 ms
4,348 KB
testcase_34 WA -
testcase_35 AC 1 ms
4,348 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 20 ms
4,480 KB
testcase_40 AC 18 ms
4,440 KB
testcase_41 AC 20 ms
5,684 KB
testcase_42 AC 20 ms
5,788 KB
testcase_43 AC 19 ms
4,464 KB
testcase_44 AC 21 ms
5,932 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#ifdef _RUTHEN
#include "debug.hpp"
#else
#define show(...) true
#endif

using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
template <class T> using V = vector<T>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    V<int> A(N);
    rep(i, N) cin >> A[i];
    V<int> ind;
    rep(i, N) {
        if (A[i] <= N / 2) {
            ind.push_back(i);
        }
    }
    if (N % 2 == 1) {
        ll ans = 0;
        rep(i, N / 2) ans += abs(ind[i] - (2 * i + 1));
        cout << N / 2 << ' ' << ans << '\n';
    } else {
        int N2 = N / 2;
        V<ll> dp(N2 + 1), rp(N2 + 1);
        for (int i = 0; i < N2; i++) dp[i + 1] = dp[i] + abs(ind[i] - (2 * i + 1));
        for (int i = N2 - 1; i >= 0; i--) dp[i] = dp[i + 1] + abs(ind[i] - (2 * i));
        ll ans = 1LL << 60;
        rep(i, N2 + 1) ans = min(ans, dp[i] + rp[i]);
        cout << N / 2 << ' ' << ans << '\n';
    }
    return 0;
}
0