結果

問題 No.2739 Time is money
ユーザー 0214sh70214sh7
提出日時 2024-04-21 03:16:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 402 ms / 2,000 ms
コード長 2,215 bytes
コンパイル時間 2,608 ms
コンパイル使用メモリ 207,900 KB
実行使用メモリ 35,564 KB
最終ジャッジ日時 2024-04-21 03:16:15
合計ジャッジ時間 9,266 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 160 ms
21,760 KB
testcase_03 AC 305 ms
30,548 KB
testcase_04 AC 150 ms
21,120 KB
testcase_05 AC 218 ms
22,536 KB
testcase_06 AC 326 ms
28,720 KB
testcase_07 AC 393 ms
34,176 KB
testcase_08 AC 385 ms
34,880 KB
testcase_09 AC 396 ms
35,188 KB
testcase_10 AC 294 ms
33,664 KB
testcase_11 AC 402 ms
35,088 KB
testcase_12 AC 313 ms
32,896 KB
testcase_13 AC 343 ms
32,896 KB
testcase_14 AC 284 ms
32,768 KB
testcase_15 AC 263 ms
33,768 KB
testcase_16 AC 251 ms
30,956 KB
testcase_17 AC 392 ms
35,436 KB
testcase_18 AC 399 ms
35,564 KB
testcase_19 AC 296 ms
33,920 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> PP;
// #define MOD 1000000007
#define MOD 998244353
#define INF 2305843009213693951
//#define INF 810114514
#define PI 3.141592653589
#define setdouble setprecision
#define REP(i,n) for(ll i=0;i<(n);++i)
#define OREP(i,n) for(ll i=1;i<=(n);++i)
#define RREP(i,n) for(ll i=(n)-1;i>=0;--i)
#define ORREP(i,n) for(ll i=(n);i>=1;--i)
#define rep(i,a,b) for(ll i=(a);i<=(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define GOODBYE do { cout << "-1" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug true
#define debug2 false


int main(void){
    //cin.tie(nullptr);
    //ios::sync_with_stdio(false);
    
    ll N,M,X;
    cin >> N >> M >> X;
    vector<ll> U(M),V(M),C(M),T(M);
    REP(i,M){
        cin >> U[i] >> V[i] >> C[i] >> T[i];
        U[i]--;V[i]--;
    }
    
    vector<vector<array<ll,3>>> G(N);
    REP(i,M){
        G[U[i]].push_back({V[i],C[i],T[i]});
        G[V[i]].push_back({U[i],C[i],T[i]});
    }
    
    // かかる時間のマイナス、余剰資金、金、時間、頂点
    priority_queue<pair<array<ll,4>,ll>> Que;
    Que.push({{0,0,0,0},0});
    
    vector<array<ll,4>> cost(N,{-INF,-INF,INF,INF});
    cost[0] = {0,0,0,0};
    
    while(!Que.empty()){
        
        auto q = Que.top();
        Que.pop();
        
        array<ll,4> p = q.first;
        ll v = q.second;
        if(cost[v] > p)continue;
        
        // cout << "? " << p[0] MM p[1] MM p[2] MM p[3] << "  " << v << endl;
        
        for(array<ll,3> g:G[v]){
            ll u = g[0], c = g[1], t=g[2];
            // cout << "  " << u MM c MM t << endl;
            ll nc = cost[v][2]+c, nt = cost[v][3]+t;
            array<ll,4> ni = {-(nt+(nc+X-1)/X),((nc+X-1)/X)*X-nc,nc,nt};
            if(cost[u] < ni){
                cost[u] = ni;
                Que.push({cost[u],u});
            }
        }
        
    }
    
    // REP(i,N){
    //     cout << i << ": ";
    //     REP(j,4){cout << cost[i][j] << " ";}cout << endl;
    // }
    
    ll Ans = -cost[N-1][0];
    if(Ans==INF)Ans=-1;
    cout << Ans << endl;
    
    
    return 0;
    
}
0