結果

問題 No.2029 Swap Min Max Min
ユーザー publfl2publfl2
提出日時 2022-08-05 21:50:26
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,212 bytes
コンパイル時間 634 ms
コンパイル使用メモリ 55,488 KB
実行使用メモリ 4,816 KB
最終ジャッジ日時 2023-10-14 00:08:14
合計ジャッジ時間 3,332 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 14 ms
4,348 KB
testcase_06 AC 28 ms
4,352 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 9 ms
4,348 KB
testcase_11 WA -
testcase_12 AC 18 ms
4,352 KB
testcase_13 WA -
testcase_14 AC 42 ms
4,704 KB
testcase_15 WA -
testcase_16 AC 40 ms
4,776 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 41 ms
4,764 KB
testcase_20 AC 42 ms
4,760 KB
testcase_21 AC 42 ms
4,752 KB
testcase_22 AC 41 ms
4,748 KB
testcase_23 AC 28 ms
4,740 KB
testcase_24 AC 27 ms
4,816 KB
testcase_25 AC 27 ms
4,744 KB
testcase_26 AC 26 ms
4,816 KB
testcase_27 AC 1 ms
4,348 KB
testcase_28 AC 1 ms
4,348 KB
testcase_29 AC 1 ms
4,352 KB
testcase_30 AC 2 ms
4,352 KB
testcase_31 AC 2 ms
4,356 KB
testcase_32 WA -
testcase_33 AC 2 ms
4,352 KB
testcase_34 AC 1 ms
4,352 KB
testcase_35 AC 1 ms
4,348 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 AC 1 ms
4,352 KB
testcase_38 AC 35 ms
4,572 KB
testcase_39 AC 38 ms
4,684 KB
testcase_40 AC 35 ms
4,604 KB
testcase_41 AC 38 ms
4,656 KB
testcase_42 AC 38 ms
4,660 KB
testcase_43 AC 37 ms
4,684 KB
testcase_44 AC 40 ms
4,720 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <vector>
#include <algorithm>

int x[200010],y[200010];
std::vector<int> V;
int main()
{
	int a;
	scanf("%d",&a);
	for(int i=1;i<=a;i++) scanf("%d",&x[i]);
	for(int i=1;i<=a;i++) y[i] = x[i];
	std::sort(y+1,y+a+1);
	int limit = y[a/2];
	
	if(a%2==1)
	{
		long long int ans = 0;
		V.clear();
		for(int i=1;i<=a;i++) if(x[i]<=limit) V.push_back(i);
		for(int i=0;i<V.size();i++) ans += abs(V[i]-(2*i+2));
		V.clear();
		for(int i=1;i<=a;i++) if(x[i]>limit) V.push_back(i);
		for(int i=0;i<V.size();i++) ans += abs(V[i]-(2*i+1));
		printf("%d %lld",limit,ans/2);
	}
	else
	{
		long long int ans1 = 0;
		V.clear();
		for(int i=1;i<=a;i++) if(x[i]<=limit) V.push_back(i);
		for(int i=0;i<V.size();i++) ans1 += abs(V[i]-(2*i+2));
		V.clear();
		for(int i=1;i<=a;i++) if(x[i]>limit) V.push_back(i);
		for(int i=0;i<V.size();i++) ans1 += abs(V[i]-(2*i+1));
		
		long long int ans2 = 0;
		V.clear();
		for(int i=1;i<=a;i++) if(x[i]<=limit) V.push_back(i);
		for(int i=0;i<V.size();i++) ans2 += abs(V[i]-(2*i+1));
		V.clear();
		for(int i=1;i<=a;i++) if(x[i]>limit) V.push_back(i);
		for(int i=0;i<V.size();i++) ans2 += abs(V[i]-(2*i+2));
		printf("%d %lld",limit,(ans1<ans2?ans1:ans2)/2);
	}
}
0