結果

問題 No.859 路線A、路線B、路線C
ユーザー tooftoof
提出日時 2019-08-09 22:15:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,021 bytes
コンパイル時間 2,229 ms
コンパイル使用メモリ 200,580 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-26 18:14:45
合計ジャッジ時間 2,817 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

int main() {
  cin.tie(0); ios::sync_with_stdio(false);

  vector<ll> d(3);
  rep(i, 3) {
    cin >> d[i];
  }
  char a, b;
  ll s, g;
  cin >> a >> s >> b >> g;
  int ss = a-'A';
  int gg = b-'A';

  ll ans = 1e10;
  if (ss == gg) {
    cmin(ans, abs(s-g));
    ll m = 1e10;
    rep(i, 3) {
      if (i != ss) cmin(m, d[i]);
    }
    cmin(ans, min(s, g) + d[ss] - max(s, g) + m);
  } else {
    cmin(ans, s+g-1);
    cmin(ans, d[ss]-s+d[ss]-g+1);
    int m;
    rep(i, 3) if (i != ss && i != gg) m = i;
    cmin(ans, s+d[m]+d[gg]-g);
    cmin(ans, d[ss]-s+d[m]+g);
  }

  cout << ans << endl;
}
0