結果
問題 | No.2739 Time is money |
ユーザー | GOTKAKO |
提出日時 | 2024-04-20 10:27:57 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 242 ms / 2,000 ms |
コード長 | 1,269 bytes |
コンパイル時間 | 2,577 ms |
コンパイル使用メモリ | 213,860 KB |
実行使用メモリ | 25,660 KB |
最終ジャッジ日時 | 2024-04-20 10:28:05 |
合計ジャッジ時間 | 7,122 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,812 KB |
testcase_02 | AC | 88 ms
16,128 KB |
testcase_03 | AC | 179 ms
22,244 KB |
testcase_04 | AC | 79 ms
15,740 KB |
testcase_05 | AC | 113 ms
16,480 KB |
testcase_06 | AC | 157 ms
20,904 KB |
testcase_07 | AC | 206 ms
24,552 KB |
testcase_08 | AC | 216 ms
24,908 KB |
testcase_09 | AC | 222 ms
25,144 KB |
testcase_10 | AC | 152 ms
24,208 KB |
testcase_11 | AC | 242 ms
25,244 KB |
testcase_12 | AC | 164 ms
23,656 KB |
testcase_13 | AC | 157 ms
23,576 KB |
testcase_14 | AC | 138 ms
23,616 KB |
testcase_15 | AC | 110 ms
23,724 KB |
testcase_16 | AC | 115 ms
21,508 KB |
testcase_17 | AC | 210 ms
25,544 KB |
testcase_18 | AC | 221 ms
25,660 KB |
testcase_19 | AC | 139 ms
23,020 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); long long N,M,X; cin >> N >> M >> X; vector<vector<tuple<int,long long,long long>>> Graph(N); for(int i=0; i<M; i++){ int u,v; cin >> u >> v; u--; v--; long long c,t; cin >> c >> t; Graph.at(u).push_back({v,c%X,t+c/X}); Graph.at(v).push_back({u,c%X,t+c/X}); } long long inf = 1e18; vector<bool> already(N); vector<pair<long long,long long>> dist(N,{inf,inf}); priority_queue<tuple<long long,long long,int>,vector<tuple<long long,long long,int>>,greater<>> Q; dist.at(0) = {0,0}; Q.push({0,0,0}); while(Q.size()){ auto[T,C,pos] = Q.top(); Q.pop(); if(already.at(pos)) continue; already.at(pos) = true; C *= -1; for(auto [to,c,t] : Graph.at(pos)){ if(already.at(to)) continue; if(C < c){if(dist.at(to) > make_pair(T+t+1,c-C-X)) dist.at(to) = {T+t+1,c-C-X},Q.push({T+t+1,c-C-X,to});} else if(dist.at(to) > make_pair(T+t,c-C)) dist.at(to) = {T+t,c-C},Q.push({T+t,c-C,to}); } } if(dist.at(N-1).first == inf) cout << -1 << endl; else cout << dist.at(N-1).first << endl; }