結果

問題 No.859 路線A、路線B、路線C
ユーザー totori_nyaatotori_nyaa
提出日時 2019-08-09 22:03:50
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,407 bytes
コンパイル時間 1,757 ms
コンパイル使用メモリ 166,008 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-26 18:07:09
合計ジャッジ時間 2,318 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

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

signed main(){
    //cout << setprecision(12) ;
    ios::sync_with_stdio(false);
	cin.tie(0);
 
    ll x,y,z;
    cin>>x>>y>>z;
    string s1,s2; ll t1,t2;
    cin>>s1>>t1>>s2>>t2;
    ll ans = 1e18;
    
    

    if(s1==s2){
        if(s1=="B") swap(x,y);
        if(s1=="C") swap(z,x);
        ans = abs(t2-t1);
        ll d1 = t1 + min(y,z) + x-t2;
        ll d2 = x-t1 +1 + min(y,z) + t2-1;
        ans = min(ans,min(d1,d2));
        cout<<ans<<endl;
    }
    else {
        ll a,b,c;
        if(s1=="A"){
            a=x;
            if(s2=="B"){
                b=y;
                c=z;
            }
            else {
                b=z,c=y;
            }
        }
        else if(s1=="B"){
            a=y;
            if(s2=="A"){
                b=x;
                c=z;
            }
            else {
                b=z;
                c=x;
            }
        }
        else {
            a=z;
            if(s2=="A"){
                b=x;
                c=y;
            }
            else {
                b=y;
                c=x;
            }
        }

        ll d1 = t1 + t2-1;
        ll d2 = t1 + c + b - t2;
        ll d3 = a - t1 + b-t2+1;
        ll d4 = a-t1  + c + t2;
        //cerr<<d1<<" "<<d2<<" "<<d3<<" "<<d4<<endl;
        ans = min(min(d1,d2),min(d3,d4));
        cout<<ans<<endl;
    }

}
0