結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 WA -
testcase_04 AC 10 ms
4,348 KB
testcase_05 AC 19 ms
4,352 KB
testcase_06 AC 38 ms
5,000 KB
testcase_07 WA -
testcase_08 AC 52 ms
5,592 KB
testcase_09 AC 15 ms
4,352 KB
testcase_10 AC 11 ms
4,348 KB
testcase_11 AC 19 ms
4,348 KB
testcase_12 AC 25 ms
4,352 KB
testcase_13 WA -
testcase_14 AC 56 ms
5,536 KB
testcase_15 AC 58 ms
5,832 KB
testcase_16 AC 56 ms
5,408 KB
testcase_17 AC 54 ms
5,664 KB
testcase_18 WA -
testcase_19 AC 56 ms
5,340 KB
testcase_20 AC 57 ms
5,352 KB
testcase_21 AC 56 ms
5,420 KB
testcase_22 AC 56 ms
5,336 KB
testcase_23 AC 59 ms
5,952 KB
testcase_24 AC 59 ms
6,020 KB
testcase_25 AC 57 ms
5,256 KB
testcase_26 AC 57 ms
5,300 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 2 ms
4,352 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 1 ms
4,352 KB
testcase_32 AC 2 ms
4,348 KB
testcase_33 AC 1 ms
4,348 KB
testcase_34 WA -
testcase_35 AC 2 ms
4,348 KB
testcase_36 AC 2 ms
4,352 KB
testcase_37 AC 2 ms
4,352 KB
testcase_38 AC 50 ms
5,604 KB
testcase_39 AC 55 ms
5,380 KB
testcase_40 AC 49 ms
5,224 KB
testcase_41 AC 52 ms
5,812 KB
testcase_42 AC 53 ms
5,916 KB
testcase_43 AC 52 ms
5,172 KB
testcase_44 AC 58 ms
6,028 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[j],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