結果

問題 No.370 道路の掃除
ユーザー pocaristpocarist
提出日時 2016-05-13 23:59:59
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,219 bytes
コンパイル時間 1,009 ms
コンパイル使用メモリ 102,580 KB
実行使用メモリ 324,828 KB
最終ジャッジ日時 2024-04-15 17:29:15
合計ジャッジ時間 4,812 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

//http://yukicoder.me/problems/780
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <limits>
#include <sstream>
#include <typeinfo>

using namespace std;

int main() {
	int N, M;
	cin >> N >> M;
	vector<int> D(M);
	for (int i = 0; i < M; i++) {
		cin >> D[i];
	}
	sort(D.begin(), D.end());
	int start = 1000000000;
	int cur = 0;
	for (int i = 0; i < M; i++) {
		if (start > abs(D[i])) {
			start = abs(D[i]);
			cur = i;
		}
	}
	typedef std::tuple<int, int, int, int, int> t; //(-ans, cur, left, right, rest)
	priority_queue<t> q;

	int ans = abs(D[cur]);
	q.push(make_tuple(-ans, cur, cur, cur, N - 1));
	while (!q.empty()) {
		int rev_ans, left, right, rest;
		tie(rev_ans, cur, left, right, rest) = q.top(); q.pop();
		ans = -rev_ans;
		if (rest == 0)
			break;
		if (left-1 >= 0) {
			int d = abs(D[left - 1] - D[cur]);
			q.push(make_tuple(rev_ans - d, left - 1, left - 1, right, rest - 1));
		}
		if (right + 1 < M) {
			int d = abs(D[right + 1] - D[cur]);
			q.push(make_tuple(rev_ans - d, right + 1, left, right + 1, rest - 1));
		}
	}
	cout << ans << endl;
	return 0;
}
0