結果

問題 No.859 路線A、路線B、路線C
ユーザー cromcrom
提出日時 2019-08-09 22:12:50
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 3,680 bytes
コンパイル時間 1,501 ms
コンパイル使用メモリ 129,920 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-26 18:12:25
合計ジャッジ時間 2,405 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <ios>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <forward_list>
#include <random>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 100005;

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

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

LL Astart();
LL Bstart();
LL Cstart();

LL x, y, z;
pair< char, LL > s, g;

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

    cin >> x >> y >> z;
    cin >> s.F >> s.S;
    cin >> g.F >> g.S;

    if( s.F == 'A' ) cout << Astart();
    if( s.F == 'B' ) cout << Bstart();
    if( s.F == 'C' ) cout << Cstart();
    cout << endl;

    return 0;
}

LL Astart() {
    LL res = LINF;
    if( g.F == 'A' ) {
        if( s.S > g.S ) swap( s, g );
        
        res = min( res, g.S - s.S );
        res = min( res, y + s.S + y + ( x - g.S ) );
        res = min( res, z + s.S + y + ( x - g.S ) );

    } else if( g.F == 'B' ) {
        res = min( res, x - s.S + 1 + y - g.S );
        res = min( res, s.S + g.S - 1 );
        res = min( res, z + s.S + y - g.S );
        res = min( res, x - s.S + z +  + g.S );

    } else {
        res = min( res, s.S + g.S - 1 );
        res = min( res, x - s.S + z - g.S + 1 );
        res = min( res, s.S + y + z - g.S );
        res = min( res, x - s.S + y + g.S );

    }
    return res;

}

LL Bstart() {
    if( g.F == 'A' ) {
        swap( s, g );
        return Astart();

    }
    LL res = LINF;

    if( g.F == 'B' ) {
        if( s.S > g.S ) swap( s, g );
        res = min( res, g.S - s.S );
        res = min( res, s.S + x + y - g.S );
        res = min( res, s.S + z + y - g.S );

    } else if( g.F == 'C' ) {
        res = min( res, s.S + x + z - g.S );
        res = min( res, y - s.S + x + g.S );
        res = min( res, s.S + g.S - 1 );
        res = min( res, y - s.S + z - g.S + 1 );

    }
    return res;

}

LL Cstart() {
    if( g.F == 'A' ) {
        swap( s, g );
        return Astart();

    }
    if( g.F == 'B' ) {
        swap( s, g );
        return Bstart();

    }

    LL res = LINF;
    if( g.S < s.S ) swap( s, g);

    res = min( res, g.S - s.S );
    res = min( res, s.S + x + z - g.S );
    res = min( res, s.S + y + z - g.S );

    return res;

}

0