結果

問題 No.2029 Swap Min Max Min
ユーザー 沙耶花沙耶花
提出日時 2022-08-05 23:16:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 61 ms / 2,000 ms
コード長 986 bytes
コンパイル時間 5,306 ms
コンパイル使用メモリ 260,128 KB
実行使用メモリ 6,180 KB
最終ジャッジ日時 2023-10-14 01:07:00
合計ジャッジ時間 9,104 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 33 ms
4,692 KB
testcase_04 AC 10 ms
4,352 KB
testcase_05 AC 19 ms
4,352 KB
testcase_06 AC 40 ms
5,160 KB
testcase_07 AC 37 ms
4,860 KB
testcase_08 AC 51 ms
5,412 KB
testcase_09 AC 15 ms
4,352 KB
testcase_10 AC 12 ms
4,352 KB
testcase_11 AC 20 ms
4,372 KB
testcase_12 AC 26 ms
4,376 KB
testcase_13 AC 54 ms
5,760 KB
testcase_14 AC 57 ms
5,316 KB
testcase_15 AC 57 ms
5,812 KB
testcase_16 AC 56 ms
5,488 KB
testcase_17 AC 54 ms
5,628 KB
testcase_18 AC 61 ms
5,948 KB
testcase_19 AC 57 ms
5,484 KB
testcase_20 AC 57 ms
5,504 KB
testcase_21 AC 57 ms
5,380 KB
testcase_22 AC 55 ms
5,288 KB
testcase_23 AC 59 ms
5,948 KB
testcase_24 AC 59 ms
5,936 KB
testcase_25 AC 58 ms
5,196 KB
testcase_26 AC 57 ms
5,388 KB
testcase_27 AC 2 ms
4,352 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 2 ms
4,352 KB
testcase_30 AC 2 ms
4,356 KB
testcase_31 AC 2 ms
4,352 KB
testcase_32 AC 1 ms
4,352 KB
testcase_33 AC 2 ms
4,352 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 1 ms
4,356 KB
testcase_36 AC 2 ms
4,352 KB
testcase_37 AC 1 ms
4,348 KB
testcase_38 AC 51 ms
5,432 KB
testcase_39 AC 55 ms
5,184 KB
testcase_40 AC 49 ms
5,032 KB
testcase_41 AC 55 ms
5,804 KB
testcase_42 AC 55 ms
6,044 KB
testcase_43 AC 54 ms
5,300 KB
testcase_44 AC 59 ms
6,180 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000000

int main() {
    
	int N;
	cin>>N;
	
	
	
	vector<int> a(N);
	vector pos(2,vector<int>());
	rep(i,N){
		cin>>a[i];
		if(a[i]<=N/2)pos[0].push_back(i);
		else pos[1].push_back(i);
	}
	
	long long ans = 1000000000000000000;
	vector<int> t;
	for(int j=0;j<N;j+=2)t.push_back(j);
	rep(i,2){
		if(pos[i].size()==t.size()){
			long long sum = 0;
			rep(j,t.size()){
				sum += abs(pos[i][j]-t[j]);
			}
			ans = min(ans,sum);
		}
	}
	if(N%2==0){
		rep(j,2){
			vector<int> x = pos[0],y = t;
			long long sum = 0;
			rep(i,x.size())sum += abs(x[i]-y[i]);
			ans = min(ans,sum);
			
			rep(i,t.size()){
				sum -= abs(x[i]-y[i]);
				y[i]++;
				sum += abs(x[i]-y[i]);
				//cout<<sum<<endl;
				ans = min(ans,sum);
			}
		}
		
	}
	cout<<N/2<<' ';
	cout<<ans<<endl;
    return 0;
}
0