結果

問題 No.859 路線A、路線B、路線C
ユーザー Y17Y17
提出日時 2019-08-09 22:13:07
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,182 bytes
コンパイル時間 2,786 ms
コンパイル使用メモリ 145,960 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-26 18:14:01
合計ジャッジ時間 2,244 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

#define int long long

vector<pair<int, int>> vec[10];

signed main(){
    int x, y, z;
    cin >> x >> y >> z;
    int memo[3] = {x, y, z};

    pair<char, int> s, t;
    cin >> s.first >> s.second;
    cin >> t.first >> t.second;


    int si = s.first-'A';
    int ti = t.first-'A';
    int vi;
    if(si != 1 && ti != 1) vi = 1;
    if(si != 2 && ti != 2) vi = 2;
    if(si != 0 && ti != 0) vi = 0;

    int a1 = s.second-1 + t.second-1 + 1;
    int a2 = memo[si] - s.second  + memo[ti] - t.second + 1;
    int a3 = s.second-1 + 1 + memo[vi] + memo[ti]-t.second;
    int a4 = memo[si]-s.second + 1 + memo[vi] + t.second-1;


    if(s.first != t.first){
        cout << min(a1, min(a2, min(a3, a4))) << endl;
    }else{
        int x, y;
        x = min(s.second, t.second);
        y = max(s.second, t.second);
        int a5 = y-x;
        int a6, a7, a8;
        a6 = a7 = a8 = LLONG_MAX;
        if(si != 0)  a6 = memo[si]-y+x-1+1+memo[0];
        if(si != 1)  a7 = memo[si]-y+x-1+1+memo[1];
        if(si != 2)  a8 = memo[si]-y+x-1+1+memo[2];

        cout << min(a5, min(a6, min(a7, a8))) << endl;

    }





    return 0;
}
0