結果
問題 | No.2739 Time is money |
ユーザー | MtSaka |
提出日時 | 2024-04-20 10:43:38 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 419 ms / 2,000 ms |
コード長 | 1,957 bytes |
コンパイル時間 | 2,293 ms |
コンパイル使用メモリ | 208,688 KB |
実行使用メモリ | 25,540 KB |
最終ジャッジ日時 | 2024-04-20 10:43:49 |
合計ジャッジ時間 | 8,929 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 161 ms
16,388 KB |
testcase_03 | AC | 287 ms
22,336 KB |
testcase_04 | AC | 163 ms
15,668 KB |
testcase_05 | AC | 212 ms
16,572 KB |
testcase_06 | AC | 316 ms
21,000 KB |
testcase_07 | AC | 374 ms
24,668 KB |
testcase_08 | AC | 368 ms
24,988 KB |
testcase_09 | AC | 419 ms
25,356 KB |
testcase_10 | AC | 292 ms
24,292 KB |
testcase_11 | AC | 359 ms
25,324 KB |
testcase_12 | AC | 300 ms
23,544 KB |
testcase_13 | AC | 290 ms
23,480 KB |
testcase_14 | AC | 261 ms
23,640 KB |
testcase_15 | AC | 232 ms
24,076 KB |
testcase_16 | AC | 252 ms
21,724 KB |
testcase_17 | AC | 354 ms
25,524 KB |
testcase_18 | AC | 384 ms
25,540 KB |
testcase_19 | AC | 311 ms
23,700 KB |
ソースコード
#include<bits/stdc++.h> #define overload(a,b,c,d,...) d #define rep1(a) for(ll _=0;_<(ll)a;++_) #define rep2(i,a) for(ll i=0;i<(ll)a;++i) #define rep3(i,a,b) for(ll i=(ll)a;i<(ll)b;++i) #define rep(...) overload(__VA_ARGS__,rep3,rep2,rep1)(__VA_ARGS__) #define rrep1(i,a) for(ll i=(ll)a-1;i>=0;--i) #define rrep2(i,a,b) for(ll i=(ll)b-1;i>=(ll)a;--i) #define rrep(...) overload(__VA_ARGS__,rrep2,rrep1)(__VA_ARGS__) #define eb emplace_back #define pb push_back #define all(v) (v).begin(),(v).end() #define rall(v) (v).rbegin(),(v).rend() #define lb(v,x) (lower_bound(all(v),x)-(v).begin()) #define ub(v,x) (upper_bound(all(v),x)-(v).begin()) using namespace std; using ll=long long; using vl=vector<ll>; using ld=long double; using i128=__int128_t; template<typename T,typename U>inline static constexpr bool chmin(T&a,const U&b){return (a>b?a=b,true:false);} template<typename T,typename U>inline static constexpr bool chmax(T&a,const U&b){return (a<b?a=b,true:false);} static constexpr ll inf=numeric_limits<ll>::max()/2; struct IOSetup{IOSetup(){ios::sync_with_stdio(false);cin.tie(nullptr);}}; static constexpr ll mod=998244353; int main(){ ll n,m,x;cin>>n>>m>>x; vector<vector<array<ll,3>>>g(n); rep(i,m){ ll u,v,c,t;cin>>u>>v>>c>>t; u--,v--; g[u].pb({v,c,t}); g[v].pb({u,c,t}); } vector<pair<ll,ll>>dist(n,{inf,inf}); dist[0]={0,0}; priority_queue<pair<pair<ll,ll>,ll>,vector<pair<pair<ll,ll>,ll>>,greater<>>pq; pq.push({dist[0],0}); while(!pq.empty()){ auto [d,v]=pq.top();pq.pop(); if(dist[v]<d)continue; for(auto [u,c,t]:g[v]){ pair<ll,ll>nxt={dist[v].first+t,dist[v].second+c}; nxt.first+=nxt.second/x; nxt.second%=x; if(chmin(dist[u],nxt))pq.push({dist[u],u}); } } ll ans=dist[n-1].first+(dist[n-1].second==0?0:1); if(ans>=inf){ cout<<-1<<endl; } else cout<<ans<<endl; }