結果

問題 No.370 道路の掃除
ユーザー めうめう🎒めうめう🎒
提出日時 2016-05-13 22:37:53
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 944 bytes
コンパイル時間 912 ms
コンパイル使用メモリ 75,896 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-22 17:32:36
合計ジャッジ時間 1,559 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define ll long long
#define INF (1 << 30)
#define INFLL (1LL << 60)

int main() {
	int n,m;
	int where[1001] = {};
	int migi[1001] = {},hida[1001] = {},s = 0;
	for(int i = 1;i < 1001;i++){
		migi[i] = INF / 2;
		hida[i] = INF / 2;
	}
	cin >> n >> m;
	for(int i = 0;i < m;i++){
		cin >> where[i];
	}
	sort(where,where + m);
	int now = 1,how = 0;
	for(int i = 0;i < m;i++){
		if(where[i] < 0) how++;
		if(where[i] == 0) s++;
	}
	for(int i = 0;i < m;i++){
		if(where[i] > 0){
			migi[now] = where[i];
			now++;
		}else{
			hida[how] = abs(where[i]);
			how--;
		}
	}

	int ans = INF;
	for(int i = 0;i <= n;i++){
		ans = min(ans,min(2*migi[i] + hida[n - s - i],2*hida[i] + migi[n - s - i]));
	}
	cout << ans << endl;
	return 0;
}
0