結果

問題 No.1 道のショートカット
ユーザー scrive66scrive66
提出日時 2015-06-09 16:33:14
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 4,105 bytes
コンパイル時間 1,434 ms
コンパイル使用メモリ 90,684 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-27 21:45:08
合計ジャッジ時間 1,963 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,500 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 1 ms
4,376 KB
testcase_39 AC 1 ms
4,376 KB
testcase_40 AC 1 ms
4,376 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 1 ms
4,376 KB
testcase_43 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// Header {{{
// includes {{{
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
// }}}
using namespace std;
// consts {{{
static const int INF = 1e9;
static const double PI = acos(-1.0);
static const double EPS = 1e-10;
// }}}
// typedefs {{{
typedef long long int LL;
typedef unsigned long long int ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<ULL> VULL;
typedef vector<VULL> VVULL;
typedef vector<double> VD;
typedef vector<VD> VVD;
typedef vector<bool> VB;
typedef vector<VB> VVB;
typedef vector<char> VC;
typedef vector<VC> VVC;
typedef vector<string> VS;
typedef vector<VS> VVS;
typedef pair<int, int> PII;
typedef complex<int> P;
// }}}
// macros & inline functions {{{
// syntax sugars {{{
#define FOR(i, b, e) for (int i = (b); i < (e); ++i)
#define FORI(i, b, e) for (int i = (b); i <= (e); ++i)
#define RFOR(i, b, e) for (int i = (b); i > (e); --i)
#define RFORI(i, b, e) for (int i = (b); i >= (e); --i)
#define REP(i, n) FOR(i, 0, n)
#define REPI(i, n) FORI(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPI(i, n) RFORI(i, n, 0)
#define OPOVER(_op, _type) inline bool operator _op (const _type &t) const
// }}}
// conversion {{{
inline int toInt(string s) {
	int v; istringstream sin(s); sin >> v; return v;
}
template<class T> inline string toString(T x) {
	ostringstream sout; sout << x; return sout.str();
}
// }}}
// array and STL {{{
#define ARRSIZE(a) ( sizeof(a) / sizeof(a[0]) )
#define F first
#define S second
#define MP(a, b) make_pair(a, b)
#define PB(e) push_back(e)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
// }}}
// for readable code {{{
#define EVEN(n) (n % 2 == 0)
#define ODD(n) (!EVEN(n))
// }}}
// string manipulation {{{
inline VS split(string s, char delimiter) {
	VS v; string t; REP(i, s.length()) {
		if (s[i] == delimiter) v.PB(t), t = ""; else t += s[i];
	} v.PB(t); return v;
}
inline string join(VS s, string j) {
	string t; REP(i, s.size()) {
		t += s[i] + j;
	} return t;
}
// }}}
// geometry {{{
#define Y real()
#define X imag()
// }}}
// 2 dimentional array {{{
P dydx4[4] = { P(-1, 0), P(0, 1), P(1, 0), P(0, -1) };
P dydx8[8] = { P(-1, 0), P(0, 1), P(1, 0), P(0, -1), P(-1, 1), P(1, 1), P(1, -1), P(-1, -1) };
int g_height, g_width;
bool in_field(P p) {
	return (0 <= p.Y && p.Y < g_height) && (0 <= p.X && p.X < g_width);
}
// }}}
// }}}

#define PRINT(s) sout << (s) << endl
#define MAX 1500

int cityNum, handMoney, edgeNum;
int s[MAX], t[MAX], y[MAX], m[MAX];

struct edge {
	int cityto;
	int cost;
	int time;
	edge(int ci, int c, int t) :cityto(ci), cost(c), time(t) {}
};
vector<vector<edge>> edges(50);

struct route {
	int cost;
	int time;
	route(int c, int t) :cost(c), time(t) {}
	OPOVER(< , route) {
		return time < t.time;
	}
};
vector<route> routes;

int mintime;
inline void calc(int pos, int cost, int time) {
	for (auto x : edges[pos]) {
		int to = x.cityto;
		int c = cost + x.cost;
		int t = time + x.time;
		if (c <= handMoney && t < mintime) {
			if (to == cityNum) {
				routes.emplace_back(c, t);
				mintime = t;
			} else {
				calc(to, c, t);
			}
		}
	}
}

int main(int argc, char** argv) {
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> cityNum >> handMoney >> edgeNum;

	REP(i, edgeNum) {
		cin >> s[i];
	}
	REP(i, edgeNum) {
		cin >> t[i];
	}
	REP(i, edgeNum) {
		cin >> y[i];
	}
	REP(i, edgeNum) {
		cin >> m[i];
	}

	REP(i, edgeNum) {
		edges[s[i]].emplace_back(t[i], y[i], m[i]);
	}

	mintime = INF;
	calc(1, 0, 0);

	if (routes.empty()) {
		cout << -1 << endl;
	} else {
		cout << mintime << endl;
	}

	return 0;
}
0