結果

問題 No.1 道のショートカット
ユーザー hotpepsihotpepsi
提出日時 2014-12-06 23:33:24
言語 C++11
(gcc 11.4.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,613 bytes
コンパイル時間 1,709 ms
コンパイル使用メモリ 76,312 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-22 11:49:08
合計ジャッジ時間 9,380 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 7 ms
4,376 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
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 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <sstream>
#include <vector>
#include <queue>

using namespace std;

typedef pair<int, int> II;
typedef pair<int, II> III;
typedef vector<int> IntVec;
typedef vector<III> IIIVec;

int main(int argc, char *argv[])
{
	string s;
	getline(cin, s);
	int N = atoi(s.c_str());
	getline(cin, s);
	int C = atoi(s.c_str());
	getline(cin, s);
	int V = atoi(s.c_str());
	IntVec S(V), T(V), Y(V), M(V);
	{
		getline(cin, s);
		stringstream ss(s);
		for (int i = 0; i < V; ++i) {
			ss >> S[i];
		}
	}
	{
		getline(cin, s);
		stringstream ss(s);
		for (int i = 0; i < V; ++i) {
			ss >> T[i];
		}
	}
	{
		getline(cin, s);
		stringstream ss(s);
		for (int i = 0; i < V; ++i) {
			ss >> Y[i];
		}
	}
	{
		getline(cin, s);
		stringstream ss(s);
		for (int i = 0; i < V; ++i) {
			ss >> M[i];
		}
	}
	IIIVec v[64];
	for (int i = 0; i < V; ++i) {
		if (Y[i] <= C) {
			v[S[i] - 1].push_back(III(-Y[i], II(T[i] - 1, M[i])));
		}
	}
	int ans = 1 << 30;
	priority_queue<III> q;
	for (int i = 0; i < v[0].size(); ++i) {
		q.push(v[0][i]);
	}
	while (q.size() > 0) {
		III current = q.top();
		q.pop();
		int pos = current.second.first;
		if (pos == N - 1) {
			ans = min(ans, current.second.second);
		}
		for (int i = 0; i < v[pos].size(); ++i) {
			III &e = v[pos][i];
			int cost = current.first + e.first;
			if (-cost <= C) {
				int time = current.second.second + e.second.second;
				q.push(III(cost, II(e.second.first, time)));
			}
		}
	}
	cout << (ans < (1<<30) ? ans : -1) << endl;
	return 0;
}
0