結果

問題 No.1 道のショートカット
ユーザー kurenai3110kurenai3110
提出日時 2016-09-10 09:29:49
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,195 bytes
コンパイル時間 474 ms
コンパイル使用メモリ 66,824 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-22 12:49:46
合計ジャッジ時間 1,947 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <cstring>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define MAX_N 51

int N, C, V;

struct Edge {
	int cost, time;
};

Edge E[MAX_N][MAX_N];
int DP[301][51];

void add_edge(int a, int b, int c,int t) {
	E[a][b].cost = c;
	E[a][b].time = t;
}

int main()
{
	cin >> N >> C >> V;
	vector<int> S(V), T(V), Y(V), M(V);
	rep(i, V)cin >> S[i];
	rep(i, V)cin >> T[i];
	rep(i, V)cin >> Y[i];
	rep(i, V)cin >> M[i];

	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= N; j++) {
			E[i][j].cost = INT32_MAX;
		}
	}
	for (int i = 0; i <= C ; i++) {
		for (int j = 1; j <= N; j++) {
			DP[i][j] = INT32_MAX;
		}
	}

	for (int i = 0; i < V; i++) {
		add_edge(S[i], T[i], Y[i], M[i]);
	}

	DP[C][1] = 0;
	
	for (int i = C; i >=0; i--) {
		for (int j = 1; j <= N; j++) {
			if (DP[i][j] == INT32_MAX) continue;

			for (int k = 1; k <= N; k++) {
				if (i - E[j][k].cost < 0)continue;

				DP[i - E[j][k].cost][k] = min(DP[i - E[j][k].cost][k], DP[i][j] + E[j][k].time);
			}
		}
	}

	int mn = INT32_MAX;
	for (int i = 0; i <= C; i++) {
		mn = min(mn, DP[i][N]);
	}

	cout << mn << endl;

    return 0;
}
0