結果

問題 No.1 道のショートカット
ユーザー chocoruskchocorusk
提出日時 2018-06-24 06:51:51
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,354 bytes
コンパイル時間 690 ms
コンパイル使用メモリ 76,992 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-27 22:15:07
合計ジャッジ時間 2,324 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#define INF 1000000000
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

struct edge{
	int from, cost, time;
};

int main()
{
	int n, c, v;
	scanf("%d", &n);
	scanf("%d", &c);
	scanf("%d", &v);
	int s[1500], t[1500], y[1500], m[1500];
	for(int i=0; i<v; i++){
		scanf("%d", &s[i]);
		s[i]--;
	}
	for(int i=0; i<v; i++){
		scanf("%d", &t[i]);
		t[i]--;
	}
	for(int i=0; i<v; i++){
		scanf("%d", &y[i]);
	}
	for(int i=0; i<v; i++){
		scanf("%d", &m[i]);
	}
	vector<edge> e[50];
	for(int i=0; i<v; i++){
		edge e1;
		e1.from=s[i];
		e1.cost=y[i];
		e1.time=m[i];
		e[t[i]].push_back(e1);
	}
	int dp[50][301];
	for(int i=0; i<n; i++){
		for(int j=0; j<=c; j++){
			dp[i][j]=INF;
		}
	}
	for(int i=0; i<n; i++){
		if(i==0){
			dp[0][0]=0;
			continue;
		}
		for(int j=0; j<e[i].size(); j++){
			int x=e[i][j].from, y0=e[i][j].cost, t0=e[i][j].time;
			for(int k=y0; k<=c; k++){
				if(dp[i][k]>dp[x][k-y0]+t0){
					dp[i][k]=dp[x][k-y0]+t0;
				}
			}
		}
	}
	int ans=INF;
	for(int k=0; k<=c; k++){
		if(ans>dp[n-1][k]) ans=dp[n-1][k];
	}
	if(ans==INF){
		printf("%d\n", -1);
	}else{
		printf("%d\n", ans);
	}
	return 0;
}
0