結果

問題 No.1 道のショートカット
ユーザー soupesuteakasoupesuteaka
提出日時 2014-12-28 13:43:09
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,320 bytes
コンパイル時間 698 ms
コンパイル使用メモリ 87,276 KB
実行使用メモリ 5,316 KB
最終ジャッジ日時 2023-09-22 11:50:42
合計ジャッジ時間 2,324 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <cstdio>
#include <sstream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#include <iomanip>

#define INF 1000000001
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
const double PI = acos(-1.0);

struct Edge {
	int to;
	int cost;
	int time;
	Edge(int a,int b,int c):to(a),cost(b),time(c){}
};

int N, C, V;
int S[1501];
int T[1501];
int Y[1501];
int M[1501];

vector<Edge> G[51];

int dp[51][301];

int main()
{
	ios::sync_with_stdio(false);

	cin >> N >> C >> V;
	FOR(i,0,V) cin >> S[i], S[i]--;
	FOR(i,0,V) cin >> T[i], T[i]--;
	FOR(i,0,V) cin >> Y[i];
	FOR(i,0,V) cin >> M[i];

	FOR(i,0,51) FOR(j,0,301) dp[i][j] = INF;
	FOR(i,0,V) {
		G[S[i]].push_back(Edge(T[i], Y[i], M[i]));
	}

	dp[0][C] = 0;
	FOR(i,0,51) RFOR(j,C,0) {
		if (dp[i][j]!=INF) {
			FOR(k,0,G[S[i]].size()) {
				Edge e = G[S[i]][k];
				if (j-e.cost>=0) {
					dp[e.to][j-e.cost] = min(dp[e.to][j-e.cost], dp[i][j]+e.time);
				}
			}
		}
	}

	int ans=INF;
	FOR(i,0,C+1) ans = min(ans, dp[N-1][i]);
	if (ans==INF) ans=-1;
	cout << ans << endl;

	return 0;
}
0