結果

問題 No.859 路線A、路線B、路線C
ユーザー beetbeet
提出日時 2019-08-09 21:42:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,376 bytes
コンパイル時間 2,987 ms
コンパイル使用メモリ 210,144 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-26 17:35:07
合計ジャッジ時間 3,931 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 WA -
testcase_10 AC 2 ms
4,376 KB
testcase_11 WA -
testcase_12 AC 2 ms
4,380 KB
testcase_13 WA -
testcase_14 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 HERE
signed 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);
  G[0].emplace_back(0,x-1);
  G[1].emplace_back(1,x-1);
  G[2].emplace_back(3,y-1);
  G[3].emplace_back(2,y-1);
  G[4].emplace_back(5,z-1);
  G[5].emplace_back(4,z-1);

  G[0].emplace_back(2,1);
  G[0].emplace_back(4,1);
  G[2].emplace_back(0,1);
  G[2].emplace_back(4,1);
  G[4].emplace_back(0,1);
  G[4].emplace_back(2,1);

  G[1].emplace_back(3,1);
  G[1].emplace_back(5,1);
  G[3].emplace_back(1,1);
  G[3].emplace_back(5,1);
  G[5].emplace_back(1,1);
  G[5].emplace_back(3,1);

  if(s0=='A'){
    G[0].emplace_back(6,t0-1);
    G[6].emplace_back(0,t0-1);
    G[1].emplace_back(6,x-t0);
    G[6].emplace_back(1,x-t0);
  }
  if(s0=='B'){
    G[2].emplace_back(6,t0-1);
    G[6].emplace_back(2,t0-1);
    G[3].emplace_back(6,y-t0);
    G[6].emplace_back(3,y-t0);
  }
  if(s0=='C'){
    G[4].emplace_back(6,t0-1);
    G[6].emplace_back(4,t0-1);
    G[5].emplace_back(6,z-t0);
    G[6].emplace_back(5,z-t0);
  }

  if(s1=='A'){
    G[0].emplace_back(7,t1-1);
    G[7].emplace_back(0,t1-1);
    G[1].emplace_back(7,x-t1);
    G[7].emplace_back(1,x-t1);
  }
  if(s1=='B'){
    G[2].emplace_back(7,t1-1);
    G[7].emplace_back(2,t1-1);
    G[3].emplace_back(7,y-t1);
    G[7].emplace_back(3,y-t1);
  }
  if(s1=='C'){
    G[4].emplace_back(7,t1-1);
    G[7].emplace_back(4,t1-1);
    G[5].emplace_back(7,z-t1);
    G[7].emplace_back(5,z-t1);
  }

  cout<<dijkstra(6,G)[7]<<endl;
  return 0;
}
0