結果
| 問題 |
No.859 路線A、路線B、路線C
|
| コンテスト | |
| ユーザー |
koyopro
|
| 提出日時 | 2020-01-19 01:30:04 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 1,000 ms |
| コード長 | 1,724 bytes |
| コンパイル時間 | 2,084 ms |
| コンパイル使用メモリ | 167,784 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-28 15:39:14 |
| 合計ジャッジ時間 | 2,374 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 |
ソースコード
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, a, b) for(int i=(b-1);i>=(a);i--)
#define REP(i, n) for(int i=0; i<(n); i++)
#define RREP(i, n) for(int i=(n-1); i>=0; i--)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define array2(type, x, y) array<array<type, y>, x>
#define vector2(type) vector<vector<type> >
#define out(...) printf(__VA_ARGS__)
int dxy[] = {0, 1, 0, -1, 0};
void solve();
signed main()
{
#if DEBUG
std::ifstream in("input.txt");
std::cin.rdbuf(in.rdbuf());
#endif
cin.tie(0);
ios::sync_with_stdio(false);
solve();
return 0;
}
/*================================*/
int A,B,C;
int L[3];
map<char,int> M;
char S[2];
int T[2];
void solve() {
REP(i,3)cin>>L[i];
REP(i,2)cin>>S[i]>>T[i];
M['A']=0;
M['B']=1;
M['C']=2;
int ans = LONG_LONG_MAX;
if (S[0]==S[1]) {
if (T[0]>T[1]) swap(T[0],T[1]);
ans = min(ans, T[1]-T[0]);
int r = M[S[0]];
int l = min(L[(r+1)%3], L[(r+2)%3]);
ans = min(ans, T[0] + l + L[r] - T[1]);
} else {
int r1 = M[S[0]];
int r2 = M[S[1]];
int r3 = 0;
while(r3==r1||r3==r2)r3++;
// 左から回る
ans = min(ans, T[0] + T[1] - 1);
// 右から回る
ans = min(ans, L[r1] - T[0] + L[r2] - T[1] + 1);
// 左から+他の線路回る
ans = min(ans, T[0] + L[r3] + L[r2] - T[1]);
// 右から+他の線路回る
ans = min(ans, L[r1] - T[0] + L[r3] + T[1]);
}
cout << ans << endl;
}
koyopro