結果
問題 | No.859 路線A、路線B、路線C |
ユーザー |
|
提出日時 | 2019-08-09 22:36:17 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 1,000 ms |
コード長 | 3,820 bytes |
コンパイル時間 | 2,485 ms |
コンパイル使用メモリ | 209,072 KB |
最終ジャッジ日時 | 2025-01-07 11:26:16 |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 |
ソースコード
#include <bits/stdc++.h>using namespace std;using ll = long long;using vi = vector<int>;using vvi = vector<vi>;using vvvi = vector<vvi>;using vll = vector<ll>;using vvll = vector<vll>;using vvvll = vector<vvll>;using vs = vector<string>;using pll = pair<ll, ll>;using vp = vector<pll>;#define rep(i, n) for(ll i = 0; i < (n); i++)#define repr(i, a, b) for(ll i = (a); i < (b); i++)#define ALL(a) (a).begin(), (a).end()#define SZ(x) ((ll)(x).size())const ll MOD = 1000000007;const ll INF = 100000000000000000LL;inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }inline ll powint(ll x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }template<class T>bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }template<class T>bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }#ifdef OJ_LOCAL#include "dump.hpp"#else#define dump(...) ((void)0)#endif// http://ronly.hatenablog.com/entry/2017/06/17/161641struct edge {ll to, cost;edge(ll t, ll c){to = t;cost = c;}};typedef vector<vector<edge> > AdjList;AdjList graph;typedef pair<ll, ll> P;vector<ll> dist;void dijkstra(ll n, ll s){dist = vector<ll>(n,INF);dist[s] = 0;priority_queue<P, vector<P>, greater<P> > que;que.push(P(0,s));while(!que.empty()){P p = que.top();que.pop();ll v = p.second;if(dist[v] < p.first){continue;}for(ll i=0;i<SZ(graph[v]);i++){edge e = graph[v][i];if(dist[e.to] > dist[v] + e.cost){dist[e.to] = dist[v] + e.cost;que.push(P(dist[e.to],e.to));}}}}int main(){cin.tie(0); ios::sync_with_stdio(false);cout << fixed << setprecision(15);ll x, y, z;cin >> x >> y >> z;char s1, s2;ll t1, t2;cin >> s1 >> t1 >> s2 >> t2;s1 -= 'A';s2 -= 'A';graph = AdjList(8);rep(i, 3)repr(j, i+1, 3){if(i != j) graph[i].emplace_back(j, 1);if(i != j) graph[j].emplace_back(i, 1);}repr(i, 3, 6)repr(j, i+1, 6){if(i != j) graph[i].emplace_back(j, 1);if(i != j) graph[j].emplace_back(i, 1);}if(s1 == s2){vll r{x, y, z};if(t1 > t2) swap(t1, t2);rep(i, 3){if(i == s1){graph[i].emplace_back(6, t1-1);graph[6].emplace_back(i, t1-1);graph[6].emplace_back(7, t2-t1);graph[7].emplace_back(6, t2-t1);graph[7].emplace_back(i+3, r[i]-t2);graph[i+3].emplace_back(7, r[i]-t2);}else{graph[i].emplace_back(i+3, r[i]-1);graph[i+3].emplace_back(i, r[i]-1);}}}else{vll r{x, y, z};rep(i, 3){if(i == s1){graph[i].emplace_back(6, t1-1);graph[6].emplace_back(i, t1-1);graph[6].emplace_back(i+3, r[i]-t1);graph[i+3].emplace_back(6, r[i]-t1);}else if(i == s2){graph[i].emplace_back(7, t2-1);graph[7].emplace_back(i, t2-1);graph[7].emplace_back(i+3, r[i]-t2);graph[i+3].emplace_back(7, r[i]-t2);}else{graph[i].emplace_back(i+3, r[i]-1);graph[i+3].emplace_back(i, r[i]-1);}}}rep(i, 8)rep(j, SZ(graph[i])){dump(i, j, graph[i][j].to, graph[i][j].cost);}dijkstra(8, 6);dump(dist);cout << dist[7] << endl;return 0;}