結果

問題 No.2029 Swap Min Max Min
ユーザー 沙耶花沙耶花
提出日時 2022-08-05 23:08:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,251 bytes
コンパイル時間 4,275 ms
コンパイル使用メモリ 261,508 KB
実行使用メモリ 6,076 KB
最終ジャッジ日時 2023-10-14 00:55:16
合計ジャッジ時間 7,527 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 WA -
testcase_04 AC 9 ms
4,348 KB
testcase_05 AC 18 ms
4,348 KB
testcase_06 AC 37 ms
5,024 KB
testcase_07 WA -
testcase_08 AC 47 ms
5,564 KB
testcase_09 AC 15 ms
4,352 KB
testcase_10 AC 11 ms
4,352 KB
testcase_11 AC 19 ms
4,352 KB
testcase_12 AC 24 ms
4,348 KB
testcase_13 WA -
testcase_14 AC 57 ms
5,392 KB
testcase_15 AC 57 ms
5,976 KB
testcase_16 AC 53 ms
5,316 KB
testcase_17 AC 53 ms
5,544 KB
testcase_18 WA -
testcase_19 AC 55 ms
5,336 KB
testcase_20 AC 55 ms
5,512 KB
testcase_21 AC 56 ms
5,444 KB
testcase_22 AC 54 ms
5,500 KB
testcase_23 AC 54 ms
5,932 KB
testcase_24 AC 59 ms
6,076 KB
testcase_25 AC 57 ms
5,388 KB
testcase_26 AC 57 ms
5,296 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 1 ms
4,348 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 2 ms
4,352 KB
testcase_32 AC 1 ms
4,348 KB
testcase_33 AC 1 ms
4,352 KB
testcase_34 WA -
testcase_35 AC 2 ms
4,356 KB
testcase_36 AC 1 ms
4,348 KB
testcase_37 AC 2 ms
4,348 KB
testcase_38 AC 49 ms
5,628 KB
testcase_39 AC 54 ms
5,536 KB
testcase_40 AC 46 ms
5,116 KB
testcase_41 AC 51 ms
5,816 KB
testcase_42 AC 53 ms
5,788 KB
testcase_43 AC 53 ms
5,324 KB
testcase_44 AC 58 ms
6,044 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);
			//cout<<i<<endl;
		}
	}
	if(N%2==0){
		{
			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);
			
			for(int i=t.size()-1;i>=0;i--){
				sum -= abs(x[i]-y[i]);
				y[i]++;
				sum += abs(x[i]-y[i]);
				ans = min(ans,sum);
			}
		}
		{
			vector<int> x = pos[1],y = t;
			long long sum = 0;
			rep(i,x.size())sum += abs(x[i]-y[i]);
			ans = min(ans,sum);
			
			for(int i=t.size()-1;i>=0;i--){
				sum -= abs(x[i]-y[i]);
				y[i]++;
				sum += abs(x[i]-y[i]);
				ans = min(ans,sum);
			}
		}
		
	}
	cout<<N/2<<' ';
	cout<<ans<<endl;
    return 0;
}
0