結果
| 問題 |
No.1 道のショートカット
|
| コンテスト | |
| ユーザー |
たこし
|
| 提出日時 | 2015-06-27 18:03:52 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 5,000 ms |
| コード長 | 1,835 bytes |
| コンパイル時間 | 836 ms |
| コンパイル使用メモリ | 95,052 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-20 16:15:50 |
| 合計ジャッジ時間 | 1,927 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 40 |
ソースコード
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <queue>
#include <complex>
#define INF 1000000007
#define INF_MAX 2147483647
#define LL_MAX 9223372036854775807
#define EPS 1e-10
#define PI acos(-1)
#define LL long long
using namespace std;
#define MAX_N 51
#define MAX_C 301
#define MAX_V 1501
int N, C, V;
int S[MAX_V], T[MAX_V], Y[MAX_V], M[MAX_V];
int dp[MAX_N][MAX_C];
typedef pair<int, int> II;
typedef pair<int, II> III;
vector<III> Edge[MAX_N];
int main(){
cin >> N >> C >> V;
for(int i = 0; i < V; i++){
cin >> S[i];
}
for(int i = 0; i < V; i++){
cin >> T[i];
}
for(int i = 0; i < V; i++){
cin >> Y[i];
}
for(int i = 0; i < V; i++){
cin >> M[i];
}
for(int i = 0; i < MAX_N; i++){
for(int j = 0; j < MAX_C; j++){
dp[i][j] = INF;
}
}
for(int i = 0; i < V; i++){
Edge[S[i]].push_back(III(T[i], II(Y[i], M[i])));
}
dp[1][0] = 0;
for(int pos = 1; pos < N; pos++){
for(int c = 0; c <= C; c++){
for(int e = 0; e < Edge[pos].size(); e++){
III edge = Edge[pos][e];
int nextPos = edge.first;
int nextCost = edge.second.first + c;
int nextTime = edge.second.second;
if(nextCost <= C){
dp[nextPos][nextCost] =
min(dp[nextPos][nextCost], nextTime + dp[pos][c]);
}
}
}
}
int ans = INF;
for(int c = 0; c <= C; c++){
ans = min(ans, dp[N][c]);
}
if(ans == INF)
cout << -1 << endl;
else
cout << ans << endl;
return 0;
}
たこし