結果

問題 No.859 路線A、路線B、路線C
ユーザー LayCurseLayCurse
提出日時 2019-08-21 05:46:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 2,627 bytes
コンパイル時間 2,554 ms
コンパイル使用メモリ 206,176 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 17:07:45
合計ジャッジ時間 3,313 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
template<class S, class T> inline S min_L(S a,T b){
  return a<=b?a:b;
}
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void rd(char &c){
  int i;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c = i;
}
inline int rd(char c[]){
  int i, sz=0;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S chmin(S &a, T b){
  if(a>b){
    a=b;
  }
  return a;
}
int X;
int Y;
int Z;
char S0;
char S1;
int T0;
int T1;
int e0;
int e1;
int main(){
  int i, j, k, res=1073709056;
  rd(X);
  rd(Y);
  rd(Z);
  rd(S0);
  rd(T0);
  rd(S1);
  rd(T1);
  if(S0=='A'){
    e0 = X - T0 + 1;
  }
  if(S0=='B'){
    e0 = Y - T0 + 1;
  }
  if(S0=='C'){
    e0 = Z - T0 + 1;
  }
  if(S1=='A'){
    e1 = X - T1 + 1;
  }
  if(S1=='B'){
    e1 = Y - T1 + 1;
  }
  if(S1=='C'){
    e1 = Z - T1 + 1;
  }
  k =min_L(min_L(X, Y), Z);
  if(S0==S1){
    chmin(res, abs(T1-T0));
  }
  chmin(res, T0 + T1 - 1);
  chmin(res, e0 + e1 - 1);
  chmin(res, (long long)T0 + k + e1 - 1);
  chmin(res, (long long)T1 + k + e0 - 1);
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190820-1

// --- original code ---
// int X, Y, Z;
// char S0, S1;
// int T0, T1;
// 
// int e0, e1;
// {
//   int i, j, k;
//   int res = int_inf;
//   rd(X,Y,Z,S0,T0,S1,T1);
// 
//   if(S0=='A') e0 = X - T0 + 1;
//   if(S0=='B') e0 = Y - T0 + 1;
//   if(S0=='C') e0 = Z - T0 + 1;
//   if(S1=='A') e1 = X - T1 + 1;
//   if(S1=='B') e1 = Y - T1 + 1;
//   if(S1=='C') e1 = Z - T1 + 1;
//   k = min(X, Y, Z);
// 
//   if(S0==S1) res <?= abs(T1-T0);
//   res <?= T0 + T1 - 1;
//   res <?= e0 + e1 - 1;
//   res <?= (ll)T0 + k + e1 - 1;
//   res <?= (ll)T1 + k + e0 - 1;
//   wt(res);
// }
0