結果

問題 No.859 路線A、路線B、路線C
ユーザー kyunakyuna
提出日時 2019-08-19 13:29:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 782 bytes
コンパイル時間 597 ms
コンパイル使用メモリ 72,264 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-14 23:28:46
合計ジャッジ時間 1,210 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    vector<long long> c(3);
    for (long long &ci: c) cin >> ci;
    char s0, s1; long long t0, t1;
    cin >> s0 >> t0 >> s1 >> t1; s0 -= 'A', s1 -= 'A';
    if (s0 == s1) {
        swap(c[0], c[s0]);
        if (t0 > t1) swap(t0, t1);
        long long ans = min(t1 - t0, t0 + min(c[1], c[2]) + c[0] - t1);
        cout << ans << endl;
    } else {
        long long x = c[s0], y = c[s1], z = c[3 - s0 - s1];
        long long ans = min({
            t0 + t1 - 1, x - t0 + y - t1 + 1,
            t0 + z + y - t1, x - t0 + z + t1
        });
        cout << ans << endl;
    }
    return 0;
}
0