結果

問題 No.859 路線A、路線B、路線C
ユーザー i_mrhji_mrhj
提出日時 2019-08-10 18:11:07
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,628 bytes
コンパイル時間 162 ms
コンパイル使用メモリ 29,648 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-26 23:30:03
合計ジャッジ時間 1,021 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) > (b) ? (b) : (a))
#define abs(x) ((x) > 0 ? (x) : -(x))
#define rep(i, n) for(int i = 0; i < (n); i++)
#define MOD 1000000007 //10^9 + 7
#define endl printf("\n")
typedef long long ll;
#define MAX_N (1 << 17)

void
swap(ll* a, ll* b){
  int tmp;
  tmp = *a;
  *a = *b;
  *b = tmp;
  return;
}

int
main(int argc, char *argv[])
{
  ll x, y, z;
  scanf("%lld %lld %lld\n", &x, &y, &z);
  char s[2], ctmp; ll t[2], tmp;
  
  
  scanf("%c", &s[0]);
  scanf("%lld\n", &t[0]);
  scanf("%c", &s[1]);
  scanf("%lld", &t[1]);
  
  if (s[0] > s[1]) {
    ctmp = s[0];
    tmp = t[0];
    s[0] = s[1];
    t[0] = t[1];
    s[1] = ctmp;
    t[1] = tmp;
  }

  ll a, b, c, d, e, f; ll ans;
  if (s[0] == s[1]) {
    ll m = Min(t[0], t[1]);
    ll M = Max(t[0], t[1]);
    a = M - m;
    if (s[0] == 'A') {
      b = m + M - x + y;
      c = m + M - x + z;
      ans = Min(a, Min(b, c));
    }
    if (s[0] == 'B') {
      b = m + M - y + x;
      c = m + M - y + z;
      ans = Min(a, Min(b, c));
    }
    if (s[0] == 'C') {
      b = m + M - z + x;
      c = m + M - z + y;
      ans = Min(a, Min(b, c));
    }
  } else {
    if (s[1] == 'B') swap(&y, &z);
    if (s[0] == 'B') {
      ll temp = x;
      x = y; y = z; z = temp;
    }

    
    a = t[0] + t[1] - 1;
    b = x - t[0] + 1 + z - t[1];
    c = t[0] - 1 + y + z - t[1] + 1;
    d = x - t[0] + y + t[1];

    ans = Min(a, Min(b, Min(c, d)));
  }

  printf("%lld\n", ans);

  return 0;
}
      
0