結果
| 問題 |
No.1 道のショートカット
|
| コンテスト | |
| ユーザー |
Ai3Shota
|
| 提出日時 | 2018-05-15 03:37:04 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 63 ms / 5,000 ms |
| コード長 | 1,039 bytes |
| コンパイル時間 | 1,311 ms |
| コンパイル使用メモリ | 157,664 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-20 16:35:52 |
| 合計ジャッジ時間 | 2,817 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 40 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef struct{
int corrent;
int next;
int money;
int tim;
}ROOT;
int N, C, V;
ROOT root[1500];
int dp[50][300] = {{0}};
int result = INT_MAX;
void rec(int corrent = 1, int money = 0, int tim = 0){
if(money > C) return;
if(corrent == N){
if(result > tim) result = tim;
return;
}
if(dp[corrent][money] != 0 && dp[corrent][money] <= tim && result <= tim) return;
dp[corrent][money] = tim;
for(int i = 0; i < V; ++i){
if(root[i].corrent == corrent) rec(root[i].next, money + root[i].money, tim + root[i].tim);
}
return;
}
int main(void){
cin >> N >> C >> V;
int i;
for(i = 0; i < V; ++i) cin >> root[i].corrent;
for(i = 0; i < V; ++i) cin >> root[i].next;
for(i = 0; i < V; ++i) cin >> root[i].money;
for(i = 0; i < V; ++i) cin >> root[i].tim;
rec();
if(result == INT_MAX) cout << -1 << endl;
else cout << result << endl;
return 0;
}
Ai3Shota