結果

問題 No.370 道路の掃除
ユーザー FF256grhyFF256grhy
提出日時 2016-05-18 20:22:08
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 989 bytes
コンパイル時間 127 ms
コンパイル使用メモリ 23,296 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-22 17:49:39
合計ジャッジ時間 1,071 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
5,248 KB
testcase_01 AC 0 ms
5,376 KB
testcase_02 AC 0 ms
5,376 KB
testcase_03 AC 0 ms
5,376 KB
testcase_04 AC 0 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 0 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 0 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 0 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 0 ms
5,376 KB
testcase_14 AC 0 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 0 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 0 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 1 ms
5,376 KB
testcase_25 AC 0 ms
5,376 KB
testcase_26 AC 1 ms
5,376 KB
testcase_27 AC 1 ms
5,376 KB
testcase_28 AC 0 ms
5,376 KB
testcase_29 AC 1 ms
5,376 KB
testcase_30 AC 1 ms
5,376 KB
testcase_31 AC 0 ms
5,376 KB
testcase_32 AC 1 ms
5,376 KB
testcase_33 AC 0 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:44:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   44 |         scanf("%d%d", &n, &m);
      |         ~~~~~^~~~~~~~~~~~~~~~
main.cpp:45:43: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   45 |         for(int i = 0; i < m; i++) { scanf("%d", &d[i]); }
      |                                      ~~~~~^~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>

int n, m, d[1000];

int e[1000];
void sort(int l, int r) {
	if(r - l < 2) { return; }
	
	int b = (l + r) / 2;
	sort(l, b);
	sort(b, r);
	
	int ll = l;
	int rr = b;
	int c = l;
	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[c] = d[ll];
			ll++;
		} else {
			e[c] = d[rr];
			rr++;
		}
		c++;
	}
	
	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