結果

問題 No.2739 Time is money
ユーザー Nzt3Nzt3
提出日時 2024-04-15 23:22:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 300 ms / 2,000 ms
コード長 952 bytes
コンパイル時間 2,608 ms
コンパイル使用メモリ 207,704 KB
実行使用メモリ 20,096 KB
最終ジャッジ日時 2024-04-15 23:23:07
合計ジャッジ時間 7,874 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 98 ms
13,312 KB
testcase_03 AC 217 ms
17,144 KB
testcase_04 AC 92 ms
12,800 KB
testcase_05 AC 143 ms
12,636 KB
testcase_06 AC 181 ms
14,888 KB
testcase_07 AC 300 ms
19,756 KB
testcase_08 AC 277 ms
20,028 KB
testcase_09 AC 279 ms
19,912 KB
testcase_10 AC 183 ms
19,200 KB
testcase_11 AC 300 ms
19,864 KB
testcase_12 AC 195 ms
17,280 KB
testcase_13 AC 193 ms
17,252 KB
testcase_14 AC 180 ms
17,280 KB
testcase_15 AC 115 ms
15,748 KB
testcase_16 AC 121 ms
16,292 KB
testcase_17 AC 276 ms
20,064 KB
testcase_18 AC 266 ms
20,096 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr int MOD=998244353;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N,M,X;
  cin>>N>>M>>X;
  vector G(N,vector(0,array<int,3>()));
  for(int i=0;i<M;i++){
    int U,V,C,T;
    cin>>U>>V>>C>>T;
    --U,--V;
    G[U].push_back({V,C,T});
    G[V].push_back({U,C,T});
  }
  vector dist(N,array<ll,2>({(ll)1e18,0ll}));
  dist[0]={0,0};
  using pq_pair=pair<array<ll,2>,int>;
  priority_queue<pq_pair,vector<pq_pair>,greater<pq_pair>>pq;
  pq.push(make_pair(array<ll,2>({0,0}),0));
  while(pq.size()){
    auto [d,v]=pq.top();
    pq.pop();
    if(d>dist[v])continue;
    for(auto [to,c,t]:G[v]){
      array<ll,2>d2=d;
      ll k=(c+d2[1]+X-1)/X;
      d2[0]+=t+k;
      d2[1]=-(k*X-d[1]-c);
      if(dist[to]>d2){
        dist[to]=d2;
        pq.push(make_pair(d2,to));
      }
    }
  }
  if(dist[N-1][0]==1e18)cout<<"-1\n";
  else cout<<dist[N-1][0]<<'\n';
}
0