結果

問題 No.1 道のショートカット
ユーザー togari_takamototogari_takamoto
提出日時 2015-12-13 03:39:48
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 15 ms / 5,000 ms
コード長 1,748 bytes
コンパイル時間 860 ms
コンパイル使用メモリ 100,592 KB
実行使用メモリ 9,120 KB
最終ジャッジ日時 2023-09-27 21:50:26
合計ジャッジ時間 2,409 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 11 ms
7,580 KB
testcase_09 AC 7 ms
5,564 KB
testcase_10 AC 5 ms
4,692 KB
testcase_11 AC 7 ms
5,712 KB
testcase_12 AC 15 ms
9,120 KB
testcase_13 AC 13 ms
8,908 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 4 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 4 ms
4,380 KB
testcase_20 AC 4 ms
4,376 KB
testcase_21 AC 4 ms
4,436 KB
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 9 ms
8,224 KB
testcase_24 AC 9 ms
8,560 KB
testcase_25 AC 6 ms
5,152 KB
testcase_26 AC 4 ms
4,796 KB
testcase_27 AC 10 ms
7,160 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 3 ms
4,380 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 3 ms
4,376 KB
testcase_32 AC 9 ms
6,412 KB
testcase_33 AC 6 ms
5,424 KB
testcase_34 AC 8 ms
7,068 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 3 ms
4,376 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 4 ms
4,380 KB
testcase_40 AC 2 ms
4,376 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 1 ms
4,376 KB
testcase_43 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <string>
#include <map>
#include <queue>
#include <iomanip>
#include <numeric>
#include <memory>
#include <limits.h>
#include <set>
#include <cassert>
#include <cmath>
#include <bitset>
#include <functional>
#include <limits>
using namespace std;

typedef long long ll;

#define REP(i,n) for(ll i=0; i<(n); ++i)
#define TEN(x) ((ll)1e##x)
#define ALL(v) (v).begin(), (v).end()

using Distance = ll;
#define INF_DIST numeric_limits<Distance>::max()
using Id = ll;
struct edge{Id to; Distance cost;};
using Graph = vector<vector<edge>>;
vector<Distance> dijkstra(Id s, const Graph & g){
	vector<Distance> d(g.size(), INF_DIST);
	d[s] = 0;
	
	using P = pair<Distance, Id>;
	priority_queue<P, vector<P>, greater<P>> que;
	que.push(P(0, s));
	while(!que.empty()){
		auto p = que.top(); que.pop();
		Id v = p.second;
		if(d[v] < p.first) continue;
		for (auto e : g[v]) if(d[e.to] > d[v] + e.cost){
			d[e.to] = d[v] + e.cost;
			que.push(P(d[e.to], e.to));
		}
	}

	return d;
}

Id calc_id(ll i, ll c, ll n) { return i + n * c; }

int main(){
	ll n, c, v;
	cin >> n >> c >> v;
	vector<ll> s(v);
	vector<ll> t(v);
	vector<ll> y(v);
	vector<ll> m(v);
	for (auto&i : s) cin >> i;
	for (auto&i : t) cin >> i;
	for (auto&i : y) cin >> i;
	for (auto&i : m) cin >> i;
	
	for (auto&i : s) --i;
	for (auto&i : t) --i;

	ll n_extended = calc_id(n,c,n);
	Graph g(n_extended);
	REP(i, v) REP(j, c + 1) if(j >= y[i]) {
		g[calc_id(s[i], j, n)].push_back({ calc_id(t[i], j - y[i], n), m[i] });
	}
	auto d = dijkstra(calc_id(0, c, n), g);

	ll min_d = INF_DIST;
	REP(i, c+1) min_d = min(min_d, d[calc_id(n - 1, i, n)]);
	cout << (min_d != INF_DIST ? min_d : -1) << endl;
	return 0;
}
0