結果
| 問題 |
No.859 路線A、路線B、路線C
|
| コンテスト | |
| ユーザー |
edamame882
|
| 提出日時 | 2019-08-10 20:52:09 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 1,000 ms |
| コード長 | 1,906 bytes |
| コンパイル時間 | 1,503 ms |
| コンパイル使用メモリ | 166,708 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-19 17:25:16 |
| 合計ジャッジ時間 | 2,127 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
//container util
#define all(x) (x).begin(),(x).end()
//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};
//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
ll x,y,z;
cin >> x >> y >> z;
char s0,s1;
ll t0,t1;
cin >> s0 >> t0 >> s1 >> t1;
ll len0 = 0; // s0がいる会社の線路の長さ
ll len1 = 0; // s1がいる会社の線路の長さ
ll len2 = 0; // s0,s1がいない会社の線路の最小の長さ
if(s0 == 'A') len0 = x;
if(s0 == 'B') len0 = y;
if(s0 == 'C') len0 = z;
if(s1 == 'A') len1 = x;
if(s1 == 'B') len1 = y;
if(s1 == 'C') len1 = z;
if(s1 == s0){
if(s1 == 'A') len2 = min(y,z);
if(s1 == 'B') len2 = min(x,z);
if(s1 == 'C') len2 = min(x,y);
}
else len2 = x + y + z - len0 - len1;
ll ans = 1e15;
// 同じ路線内での距離
if(s1 == s0) ans = min(abs(t0-t1),ans);
ans = min(ans, t0 + t1 - 1); // 1
ans = min(ans, (len0 - t0 + 1) + (len1 - t1 + 1) - 1); // 2: 1の逆
ans = min(ans, t0 + (len2 + 1) + (len1 - t1 + 1) - 2); // 3: len2を使いt1が逆からいく
ans = min(ans, (len0 - t0 + 1) + (len2 + 1) + t1 - 2); // 3: len2を使いt0が逆からいく
cout << ans << endl;
return 0;
}
edamame882