結果
問題 | No.2739 Time is money |
ユーザー |
|
提出日時 | 2024-04-21 13:25:02 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 387 ms / 2,000 ms |
コード長 | 2,211 bytes |
コンパイル時間 | 5,214 ms |
コンパイル使用メモリ | 323,984 KB |
実行使用メモリ | 25,688 KB |
最終ジャッジ日時 | 2024-10-13 12:01:24 |
合計ジャッジ時間 | 12,068 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 18 |
ソースコード
#include <bits/stdc++.h>#include <atcoder/all>using mint = atcoder::modint998244353;//using mint = atcoder::modint1000000007;using namespace atcoder;using namespace std;using ll = long long;using pi = pair<int,int>;using pl = pair<ll,ll>;using vi = vector<int>;using vm = vector<mint>;using vvi = vector<vi>;using vl = vector<ll>;using vvl = vector<vl>;using vpi = vector<pair<int,int>>;using vpl = vector<pair<ll,ll>>;#define rep(i,n) for (ll i = 0; i < n; i++)#define replr(i,l,r) for (ll i = l; i < r; i++)set<char> abc = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};const int inf =1e9;const ll infl = 4e18;template <typename T>bool chmax(T &a, const T& b) {if (a < b) {a = b; return true;}return false;}template <typename T>bool chmin(T &a, const T& b) {if (a > b) {a = b; return true;}return false;}template <typename T>T max(vector<T> &v) {T m = 0;for (auto x : v) chmax(m, x);return m;}template <typename T>T min(vector<T> &v) {T m = inf;for (auto x : v) chmin(m, x);return m;}template <typename T>void print(vector<T> &v){for(auto x : v){cout<<x<<' ';}cout<<'\n';}/*memo最小回数稼いだ時の(t,-x)でダイクストラ*/struct edge{int to;ll cost;ll time;};int main(){int N,M,X; cin >> N >> M >> X;vector<vector<edge>> G(N);rep(i,M){int a,b,c,t; cin >> a >> b >> c >> t;a--; b--;G[a].push_back({b,c,t});G[b].push_back({a,c,t});}vector<pair<ll,ll>> dist(N,{infl,infl});dist[0] = {0,0};priority_queue<pair<pair<ll,ll>,int>,vector<pair<pair<ll,ll>,int>>,greater<pair<pair<ll,ll>,int>>> pq;pq.push({{0,0},0});while(!pq.empty()){auto [d,v] = pq.top(); pq.pop();if(dist[v] < d) continue;ll t=d.first,x=-d.second;for(auto e : G[v]){ll nt = t + (max(e.cost-x,(ll)0)+X-1)/X+e.time;ll nx = x + (max(e.cost-x,(ll)0)+X-1)/X*X-e.cost;if(chmin(dist[e.to],{nt,-nx})){pq.push({dist[e.to],e.to});}}}if (dist[N-1].first == infl) cout << -1 << endl;else cout << dist[N-1].first << endl;}