結果

問題 No.1 道のショートカット
ユーザー fantasiabaeticafantasiabaetica
提出日時 2018-07-06 18:53:11
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,357 bytes
コンパイル時間 405 ms
コンパイル使用メモリ 61,256 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-22 13:21:41
合計ジャッジ時間 1,917 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <climits>
#include <queue>
#include <vector>
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define p_int pair<int, int>
using namespace std;

int main(){
    // 街の数、コスト上限、道の数
    int city_n, c_max, load_n;
    cin >> city_n >> c_max >> load_n;
    // 始点、終点、コスト、時間
    int s[load_n], t[load_n], c[load_n], time[load_n];
    REP(i, 0, load_n) cin >> s[i];
    REP(i, 0, load_n) cin >> t[i];
    REP(i, 0, load_n) cin >> c[i];
    REP(i, 0, load_n) cin >> time[i];

    // 現在地を縦軸、使った費用を横軸に取ってDP
    int dp[city_n + 1][c_max + 1];
    REP(i, 0, city_n + 1){
        REP(j, 0, c_max + 1){
            dp[i][j] = INT_MAX;
        }
    }
    dp[1][0] = 0;
    REP(i, 1, city_n) {
        REP(j, 0, c_max) {
          if (dp[i][j] == INT_MAX) break;
          // i番の都市を始点とする辺を調べる
          REP(k, 0, load_n){
            if (i == s[k] && j + c[k] <= c_max){
              dp[t[k]][j + c[k]] = min(dp[t[k]][j + c[k]], dp[i][j] + time[k]);
            }
          }
        }
    }

    // dp[city_n][i]における最小値を返す
    int ans = INT_MAX;
    REP(i, 0, c_max + 1){
        ans = min(ans, dp[city_n][i]);
    }
    if (ans == INT_MAX) cout << -1 << endl;
    else cout << ans << endl;

    return 0;
}
0