結果
問題 | No.859 路線A、路線B、路線C |
ユーザー |
![]() |
提出日時 | 2019-08-09 22:31:41 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 1,000 ms |
コード長 | 1,870 bytes |
コンパイル時間 | 2,369 ms |
コンパイル使用メモリ | 206,048 KB |
最終ジャッジ日時 | 2025-01-07 11:25:44 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 |
ソースコード
#include<bits/stdc++.h>using namespace std;using Int = long long;template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}template <typename T>vector<T> dijkstra(Int s,vector<vector<pair<Int, T> > > & G){const T INF = numeric_limits<T>::max();using P = pair<T, Int>;Int n=G.size();vector<T> d(n,INF);vector<Int> b(n,-1);priority_queue<P,vector<P>,greater<P> > q;d[s]=0;q.emplace(d[s],s);while(!q.empty()){P p=q.top();q.pop();Int v=p.second;if(d[v]<p.first) continue;for(auto& e:G[v]){Int u=e.first;T c=e.second;if(d[u]>d[v]+c){d[u]=d[v]+c;b[u]=v;q.emplace(d[u],u);}}}return d;}//INSERT ABOVE HEREsigned main(){Int x,y,z;cin>>x>>y>>z;char s0,s1;Int t0,t1;cin>>s0>>t0;cin>>s1>>t1;Int n=8;using P = pair<Int, Int>;vector< vector<P> > G(n);vector<Int> vs({x,x,y,y,z,z});for(Int k=0;k<6;k+=2){G[k+0].emplace_back(k+1,vs[k]-1);G[k+1].emplace_back(k+0,vs[k]-1);}for(Int k=0;k<2;k++){G[0+k].emplace_back(2+k,1);G[0+k].emplace_back(4+k,1);G[2+k].emplace_back(0+k,1);G[2+k].emplace_back(4+k,1);G[4+k].emplace_back(0+k,1);G[4+k].emplace_back(2+k,1);}for(Int k=0;k<6;k+=2){if(s0=='A'+(k/2)){G[k+0].emplace_back(6,t0-1);G[6].emplace_back(k+0,t0-1);G[k+1].emplace_back(6,vs[k]-t0);G[6].emplace_back(k+1,vs[k]-t0);}if(s1=='A'+(k/2)){G[k+0].emplace_back(7,t1-1);G[7].emplace_back(k+0,t1-1);G[k+1].emplace_back(7,vs[k]-t1);G[7].emplace_back(k+1,vs[k]-t1);}}if(s0==s1){G[6].emplace_back(7,abs(t0-t1));G[7].emplace_back(6,abs(t0-t1));}cout<<dijkstra(6,G)[7]<<endl;return 0;}