結果
| 問題 |
No.1 道のショートカット
|
| コンテスト | |
| ユーザー |
d2verb
|
| 提出日時 | 2015-05-05 01:02:42 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,590 bytes |
| コンパイル時間 | 717 ms |
| コンパイル使用メモリ | 86,328 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-08 03:55:56 |
| 合計ジャッジ時間 | 1,973 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 37 WA * 3 |
ソースコード
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <limits>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <complex>
using namespace std;
#define INF (INT_MAX/3)
#define PI (2*acos(0.0))
#define EPS (1e-8)
typedef long long ll;
typedef unsigned long long ull;
int N, C, V, data[4][1500], memo[51][301];
struct edge{
int to, cost, time;
edge(int to, int cost, int time){
this->to = to;
this->cost = cost;
this->time = time;
}
};
vector<edge> G[51];
int solve(int n, int c){
if(memo[n][c] != INF) return memo[n][c];
if(n == N && c <= C) return 0;
if(c > C) return INF;
int _min = INF;
for(int i = 0; i < G[n].size(); i++){
_min = min(solve(G[n][i].to, c + G[n][i].cost) + G[n][i].time, _min);
}
return memo[n][c] = _min;
}
void init(){
for(int i = 0; i <= 50; i++){
for(int j = 0; j <= 300; j++) memo[i][j] = INF;
}
}
int main(){
ios_base::sync_with_stdio(0);
cin >> N >> C >> V;
for(int i = 0; i < 4; i++){
for(int j = 0; j < V; j++) cin >> data[i][j];
}
for(int i = 0; i < V; i++){
int s = data[0][i], t = data[1][i];
int y = data[2][i], m = data[3][i];
G[s].push_back(edge(t, y, m));
}
init();
int ans = solve(1, 0);
if(ans == INF) cout << -1 << endl;
else cout << ans << endl;
return 0;
}
d2verb