結果

問題 No.370 道路の掃除
ユーザー FF256grhyFF256grhy
提出日時 2016-05-13 23:05:14
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 976 bytes
コンパイル時間 724 ms
コンパイル使用メモリ 26,068 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-07-28 07:33:31
合計ジャッジ時間 2,039 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

int n, m, d[10000];


int e[10000];
void sort(int l, int r) {
	if(l + 1 == r) { return; }
	
	int b = (l + r) / 2;
	sort(l, b);
	sort(b, r);
	
	int ll = l;
	int rr = b;
	while( ! (ll == b && rr == r) ) {
		bool flag;
		if( rr == r ) {
			flag = true;
		} else if( ll == b ) {
			flag = false;
		} else {
			flag = d[ll] <= d[rr];
		}
		
		if(flag) {
			e[ll] = d[ll];
			ll++;
		} else {
			e[rr] = d[rr];
			rr++;
		}
	}
	
	for(int i = l; i < r; i++) {
		d[i] = e[i];
	}
	
	return;
}

int main() {
	scanf("%d%d", &n, &m);
	for(int i = 0; i < m; i++) { scanf("%d", &d[i]); }
	
	sort(0, m);
	
	int min = 30001;
	for(int i = 0; i + (n - 1) < m; i++) {
		int a = d[i], b = d[i + (n - 1)];
		if(a <= 0 && b <= 0) {
			if(-a < min) { min = -a; }
		} else if(0 <= a && 0 <= b) {
			if(b < min) { min = b; } 
		} else {
			int c = -a * 2 + b;
			if(c < min) { min = c; }
			c = -a + b * 2;
			if(c < min) { min = c; }
		}
	}
	
	printf("%d\n", min);
	
	return 0;
}
0