結果

問題 No.859 路線A、路線B、路線C
ユーザー rodearodea
提出日時 2020-10-12 15:54:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,104 bytes
コンパイル時間 1,366 ms
コンパイル使用メモリ 117,136 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-27 23:42:40
合計ジャッジ時間 2,162 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

#define all(a) (a).begin(), (a).end()

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

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

    ll x, y, z; cin>>x>>y>>z;
    vector<pair<char, ll>> st(2);
    cin>>st[0].first>>st[0].second>>st[1].first>>st[1].second;

    sort(all(st));

    vector<char> s(2);
    vector<ll> t(2);
    for(int i=0; i<2; i++){
        tie(s[i], t[i]) = st[i];
    }

    ll ans = 0;
    ll tmi = min(t[0], t[1]), tma = max(t[0], t[1]);
    if(s[0] == 'A'){
        if(s[1] == 'A'){
            ans = min({tma - tmi, tmi + (x - tma) + y, tmi + (x - tma) + z});
        }
        else if(s[1] == 'B'){
            ans = min({(x - t[0]) + (y - t[1]) + 1, t[0] + t[1] - 1, t[0] + z + (y - t[1])});
        }
        else{
            ans = min({(x - t[0]) + (z - t[1]) + 1, t[0] + y + (z - t[1]), t[0] + t[1] - 1});
        }
    }
    else if(s[0] == 'B'){
        if(s[1] == 'B'){
            ans = min({tma - tmi, tmi + (y - tma) + x, tmi + (y - tma) + z});
        }
        else{
            ans = min({(y - t[0]) + (z - t[1]) + 1, t[0] + x + (z - t[1]), t[0] + t[1] - 1});
        }
    }
    else{
        ans = min({tma - tmi, tmi + (z - tma) + x, tmi + (z - tma) + y});
    }

    cout << ans << endl;

    return 0;
}
0