結果

問題 No.859 路線A、路線B、路線C
ユーザー edamame882edamame882
提出日時 2019-08-10 20:51:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,906 bytes
コンパイル時間 1,442 ms
コンパイル使用メモリ 164,328 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-26 23:41:35
合計ジャッジ時間 2,380 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll x,y,z;
  cin >> x >> y >> z;
  char s0,s1;
  ll t0,t1;
  cin >> s0 >> t0 >> s1 >> t1;

  ll len0 = 0; // s0がいる会社の線路の長さ
  ll len1 = 0; // s1がいる会社の線路の長さ
  ll len2 = 0; // s0,s1がいない会社の線路の最小の長さ

  if(s0 == 'A') len0 = x;
  if(s0 == 'B') len0 = y;
  if(s0 == 'C') len0 = z;

  if(s1 == 'A') len1 = x;
  if(s1 == 'B') len1 = y;
  if(s1 == 'C') len1 = z;

  if(s1 == s0){
    if(s1 == 'A') len2 = min(y,z);
    if(s1 == 'B') len2 = min(x,z);
    if(s1 == 'C') len2 = min(x,y);
  }
  else len2 = x + y + z - len0 - len2;

  ll ans = 1e15;

  // 同じ路線内での距離
  if(s1 == s0) ans = min(abs(t0-t1),ans);

  ans = min(ans, t0 + t1 - 1); // 1
  ans = min(ans, (len0 - t0 + 1) + (len1 - t1 + 1) - 1); // 2: 1の逆
  ans = min(ans, t0 + (len2 + 1) + (len1 - t1 + 1) - 2); // 3: len2を使いt1が逆からいく
  ans = min(ans, (len0 - t0 + 1) + (len2 + 1) + t1 - 2); // 3: len2を使いt0が逆からいく
  cout << ans << endl;
  return 0;
}
0