結果

問題 No.1 道のショートカット
ユーザー hotpepsihotpepsi
提出日時 2014-12-06 23:33:24
言語 C++11
(gcc 13.3.0)
結果
MLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,613 bytes
コンパイル時間 887 ms
コンパイル使用メモリ 75,188 KB
実行使用メモリ 795,272 KB
最終ジャッジ日時 2024-07-08 03:38:06
合計ジャッジ時間 7,597 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 7 MLE * 1 -- * 32
権限があれば一括ダウンロードができます

ソースコード

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