結果

問題 No.2029 Swap Min Max Min
ユーザー XDXD
提出日時 2022-12-31 18:35:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 953 bytes
コンパイル時間 1,561 ms
コンパイル使用メモリ 164,576 KB
実行使用メモリ 12,904 KB
最終ジャッジ日時 2023-08-17 18:09:35
合計ジャッジ時間 6,348 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,460 KB
testcase_01 AC 3 ms
5,648 KB
testcase_02 AC 2 ms
5,716 KB
testcase_03 AC 15 ms
10,196 KB
testcase_04 AC 6 ms
6,464 KB
testcase_05 AC 10 ms
9,128 KB
testcase_06 AC 20 ms
10,804 KB
testcase_07 AC 18 ms
10,660 KB
testcase_08 AC 24 ms
12,016 KB
testcase_09 AC 8 ms
7,016 KB
testcase_10 AC 7 ms
6,612 KB
testcase_11 AC 11 ms
9,136 KB
testcase_12 AC 12 ms
9,632 KB
testcase_13 AC 26 ms
12,244 KB
testcase_14 AC 27 ms
12,660 KB
testcase_15 AC 28 ms
12,548 KB
testcase_16 AC 27 ms
12,688 KB
testcase_17 AC 25 ms
12,336 KB
testcase_18 AC 29 ms
12,820 KB
testcase_19 AC 27 ms
12,656 KB
testcase_20 AC 27 ms
12,652 KB
testcase_21 AC 27 ms
12,820 KB
testcase_22 AC 27 ms
12,560 KB
testcase_23 AC 26 ms
12,904 KB
testcase_24 AC 26 ms
12,840 KB
testcase_25 AC 26 ms
12,904 KB
testcase_26 AC 27 ms
12,776 KB
testcase_27 AC 2 ms
5,528 KB
testcase_28 AC 3 ms
5,572 KB
testcase_29 AC 2 ms
5,456 KB
testcase_30 AC 2 ms
5,468 KB
testcase_31 AC 2 ms
5,472 KB
testcase_32 AC 2 ms
5,468 KB
testcase_33 AC 2 ms
5,436 KB
testcase_34 AC 2 ms
5,460 KB
testcase_35 AC 2 ms
5,452 KB
testcase_36 AC 2 ms
5,728 KB
testcase_37 AC 2 ms
5,448 KB
testcase_38 AC 23 ms
12,144 KB
testcase_39 AC 25 ms
12,784 KB
testcase_40 AC 23 ms
12,092 KB
testcase_41 AC 25 ms
12,348 KB
testcase_42 AC 25 ms
12,428 KB
testcase_43 AC 25 ms
12,468 KB
testcase_44 AC 26 ms
12,812 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define forn(i,s,t) for(int i=(s); i<=(t); ++i)
#define form(i,s,t) for(int i=(s); i>=(t); --i)
#define rep(i,s,t) for(int i=(s); i<(t); ++i)
using namespace std;
typedef long long i64;
const int N = 2e5 + 5;
i64 ans;
int n; i64 a[N], r[N], pre[N], suf[N], Pr[N], Sf[N];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cin >> n; ans = 1e18;
	forn (i, 1, n) cin >> a[i];
	forn (i, 1, n) if (a[i] > n / 2) r[i] = 1;
	forn (i, 1, n) if (i & 1) Pr[i] = 1; else Sf[i] = 1;
	forn (i, 1 ,n) pre[i] = r[i] + pre[i - 1], Pr[i] += Pr[i - 1];
	form (i, n, 1) suf[i] = r[i] + suf[i + 1], Sf[i] += Sf[i + 1];
	if (n & 1) {
		ans = 0;
		forn (i, 1, n) ans += abs(Pr[i] - pre[i]);
	} else {
		forn (i, 1, n) Pr[i] = Pr[i - 1] + abs(Pr[i] - pre[i]);
		form (i, n, 1) Sf[i] = Sf[i + 1] + abs(Sf[i] - suf[i]);
		forn (i, 0, n) ans = min(ans, Pr[i] + Sf[i + 1]);
	}
	cout << (n / 2) << ' ' << ans << '\n';
	return 0;
}
/*
*/
0