結果

問題 No.1 道のショートカット
ユーザー ama_nukoama_nuko
提出日時 2018-06-14 02:25:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,487 bytes
コンパイル時間 799 ms
コンパイル使用メモリ 96,484 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-22 13:19:56
合計ジャッジ時間 2,275 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

signed main(){
    int n, c, v;
    cin >> n >> c >> v;

    vector<int> s(v), t(v), y(v), m(v);
    rep(i, v){
        cin >> s[i];
    }
    rep(i, v){
        cin >> t[i];
    }
    rep(i, v){
        cin >> y[i];
    }
    rep(i, v){
        cin >> m[i];
    }
    vector<vector<int>> dpY(n+1, vector<int>(n+1, INF));
    vector<vector<int>> dpM(n+1, vector<int>(n+1, INF));
    rep(i, v){
        dpY[s[i]][t[i]] = y[i];
        dpM[s[i]][t[i]] = m[i];
    }

    for(int k = 1; k <= n; k++){
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= n; j++){
                if(dpM[i][j] > dpM[i][k] + dpM[k][j] &&
                        dpY[i][k] + dpY[k][j] <= c){
                    dpM[i][j] = dpM[i][k] + dpM[k][j];
                    dpY[i][j] = dpY[i][k] + dpY[k][j];
                }
                if(dpM[i][j] == dpM[i][k] + dpM[k][j] &&
                        dpY[i][j] > dpY[i][k] + dpY[k][j]){
                    dpY[i][j] = dpY[i][k] + dpY[k][j];
                }
            }
        }
    }
    if(dpY[1][n] > c){
        cout << -1 << endl;
        return 0;
    }
    cout << dpM[1][n] << endl;

    return 0;
}
0