結果

問題 No.1 道のショートカット
ユーザー data9824
提出日時 2015-06-10 04:36:15
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,192 bytes
コンパイル時間 532 ms
コンパイル使用メモリ 64,124 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-07-08 04:06:52
合計ジャッジ時間 1,621 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 WA * 1
other AC * 16 WA * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using namespace std;

int n;
int costs[51][51];
int times[51][51];

int scan(int city, int cost, int time) {
	if (city == n) {
		return time;
	}
	int minTime = numeric_limits<int>::max();
	for (int next = city + 1; next <= n; ++next) {
		if (costs[city][next] != numeric_limits<int>::max()) {
			if (costs[city][next] <= cost) {
				minTime = min(minTime,
					scan(next, cost - costs[city][next], time + times[city][next]));
			}
		}
	}
	return minTime;
}

int main() {
	int c, v;
	cin >> n >> c >> v;
	vector<int> s(v);
	for (int i = 0; i < v; ++i) {
		cin >> s[i];
	}
	vector<int> t(v);
	for (int i = 0; i < v; ++i) {
		cin >> t[i];
	}
	vector<int> y(v);
	for (int i = 0; i < v; ++i) {
		cin >> y[i];
	}
	vector<int> m(v);
	for (int i = 0; i < v; ++i) {
		cin >> m[i];
	}
	fill(&costs[0][0], &costs[n][n] + 1, numeric_limits<int>::max());
	fill(&times[0][0], &times[n][n] + 1, numeric_limits<int>::max());
	for (int i = 0; i < v; ++i) {
		costs[s[i]][t[i]] = y[i];
		times[s[i]][t[i]] = m[i];
	}
	int result = scan(1, c, 0);
	cout << ((result == numeric_limits<int>::max()) ? -1 : result) << endl;
	return 0;
}
0