結果

問題 No.370 道路の掃除
ユーザー Grun1396Grun1396
提出日時 2016-08-17 10:06:13
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,476 bytes
コンパイル時間 499 ms
コンパイル使用メモリ 62,024 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-25 08:18:56
合計ジャッジ時間 1,477 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>



#define MAX_M 1000
using namespace std;

int main(){
	int n,m;
	cin >> n;//ひろうゴミの数
	cin >> m;//落ちているゴミの総数
	int D[MAX_M];
	int min_len = 9999999;
	int len = 0;
	for(int d = 0; d < m; d++) cin >> D[d];

	/*
		N個のごみを拾うための最短距離
		距離がマイナスのところのゴミを拾うとき、
	*/

	sort(D, D + m);//とりあえずソートする()
		
	/*
		距離がマイナスのところだけをひろう → 一番遠いところのABS取る
		距離がプラスのところだけをひろう →一番遠いところのABSを取る
		距離がプラスとマイナスのところをひろう → マイナスの座標の絶対値の2倍+プラスの座標が答え(一回戻る必要がある)
	*/

//	cout << endl;
	for(int d = 0; d < m - n + 1; d++){
//		cout << "D[" << d << "] :" << D[d];
//		cout << " | D[" << d + n - 1 << "] :" << D[d+n-1] << endl;
		if(D[d] <= 0 && D[d+n-1] <= 0){//座標がマイナスのところだけ
			len = -D[d];
		}
		else if(D[d] >= 0 && D[d+n-1] >= 0){//座標がプラスのところだけ
			len = D[d+n-1];
		} 		
		else {
			len = D[d+n-1] - D[d] * 2;//マイナスの座標のぶんだけ最初行ってからでないとだめ
		}

		if(len < min_len){
			 min_len = len;
//			 cout << "更新 ";
		}
//		cout << "len:" << len << endl;
		len = 0;
	}	


	cout << min_len << endl;
	return 0;
}
0