結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 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,704 KB
testcase_09 AC 7 ms
5,456 KB
testcase_10 AC 4 ms
4,648 KB
testcase_11 AC 7 ms
5,692 KB
testcase_12 AC 14 ms
9,256 KB
testcase_13 AC 14 ms
8,796 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 4 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 3 ms
4,376 KB
testcase_19 AC 3 ms
4,408 KB
testcase_20 AC 4 ms
4,380 KB
testcase_21 AC 5 ms
4,380 KB
testcase_22 AC 4 ms
4,376 KB
testcase_23 AC 9 ms
7,976 KB
testcase_24 AC 11 ms
8,328 KB
testcase_25 AC 6 ms
5,196 KB
testcase_26 AC 5 ms
4,744 KB
testcase_27 AC 9 ms
7,256 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 4 ms
4,376 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 3 ms
4,376 KB
testcase_32 AC 8 ms
6,356 KB
testcase_33 AC 6 ms
5,400 KB
testcase_34 AC 9 ms
6,972 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 3 ms
4,376 KB
testcase_37 AC 3 ms
4,380 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 4 ms
4,376 KB
testcase_40 AC 2 ms
4,384 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 AC 2 ms
4,376 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>
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()

#define INF_DIST 10000
using Distance = ll;
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