結果

問題 No.859 路線A、路線B、路線C
ユーザー cotton_fn_cotton_fn_
提出日時 2019-08-09 22:01:56
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,556 bytes
コンパイル時間 1,087 ms
コンパイル使用メモリ 110,248 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-26 18:05:55
合計ジャッジ時間 1,864 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 xs[3];
i64 s0, t0, s1, t1;
int main() {
  read_n(xs, 3);
  char c0, c1;
  cin >> c0 >> t0 >> c1 >> t1;
  s0 = c0 - 'A';
  s1 = c1 - 'A'; 
  if (t0 > t1) {
    swap(s0, s1);
    swap(t0, t1);
  }
  i64 ans;
  if (s0 == s1) {
    if (s0 != 0) {
      swap(xs[0], xs[s0]);
    }
    ans = min(t1 - t0, t0 + min(xs[1], xs[2]) + xs[0] - t1);
  } else {
    if (s0 != 0) {
      swap(xs[0], xs[s0]);
      if (s1 == 0) s1 = s0;
    }
    if (s1 != 1) {
      swap(xs[1], xs[s1]);
    }
    ans = min({
        t0 + t1 - 1,
        xs[0] - t0 + xs[1] - t1 + 1,
        t0 + xs[2] + xs[1] - t1,
        t1 + xs[2] + xs[0] - t0,
    });
  }

  cout << ans << endl;
  return 0;
}
0