結果

問題 No.859 路線A、路線B、路線C
ユーザー tarattata1tarattata1
提出日時 2019-08-09 22:02:37
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,572 bytes
コンパイル時間 1,596 ms
コンパイル使用メモリ 72,192 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-26 18:06:42
合計ジャッジ時間 1,815 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;

int x,y,z;

void calc( char* str0, int p0, ll& dist0, ll& dist1 )
{
    if(str0[0]=='A') {
        dist0+=p0;
        dist1+=(x-p0);
    }
    else if(str0[0]=='B') {
        dist0+=p0;
        dist1+=(y-p0);
    }
    else {
        dist0+=p0;
        dist1+=(z-p0);
    }
    return;
}

int main(int argc, char* argv[])
{    
    scanf("%d%d%d", &x, &y, &z);

    char str0[5]={0}, str1[5]={0};
    int  p0, p1;
    scanf("%s %d", str0, &p0);
    scanf("%s %d", str1, &p1);

    int cnt[3]={0};
    cnt[str0[0]-'A']++;
    cnt[str1[0]-'A']++;

    ll dist=LINF;
    if(str0[0]==str1[0]) {
        dist = abs(p0-p1);
    }
    {
        ll dist00=0, dist01=0, dist10=0, dist11=0;
        calc(str0, p0, dist00, dist01);
        calc(str1, p1, dist10, dist11);
        
        dist=MIN(dist, dist00+dist10-1);
        dist=MIN(dist, dist01+dist11+1);

        int k;
        for(k=0; k<3; k++) {
            ll L=(k==0? x: (k==1? y: z));
            dist=MIN(dist, dist00+dist11+L);
            dist=MIN(dist, dist10+dist01+L);
        }

        printf("%lld\n", dist);
    }
    return 0;
}
0