結果
問題 | No.859 路線A、路線B、路線C |
ユーザー |
|
提出日時 | 2019-11-16 10:18:47 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 1,000 ms |
コード長 | 1,056 bytes |
コンパイル時間 | 1,527 ms |
コンパイル使用メモリ | 166,976 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-24 23:16:41 |
合計ジャッジ時間 | 2,200 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main() { int x, y, z; cin>>x>>y>>z; char s0, s1; long t0, t1; cin>>s0>>t0; cin>>s1>>t1; if (s0 > s1) { swap(s0, s1); swap(t0, t1); } else if (s0 == s1) { if (t0 > t1) { swap(t0, t1); } } long ans = x + y + z; if (s0 == 'A') { if (s1 == 'A') { ans = min(t1 - t0, t0 + y + x - t1); ans = min(t0 + z + x - t1, ans); } else if (s1 == 'B') { ans = min(t0 + t1 - 1, x - t0 + y - t1 + 1); ans = min(t0 + z + y - t1, ans); } else { ans = min(t0 + t1 - 1, x - t0 + z - t1 + 1); ans = min(t0 + y + z - t1, ans); ans = min(x - t0 + y + t1, ans); } } else if (s0 == 'B') { if (s1 == 'B') { ans = min(t1 - t0, t0 + x + y - t1); ans = min(t0 + z + y - t1, ans); } else if (s1 == 'C') { ans = min(t0 + t1 - 1, y - t0 + z - t1 + 1); ans = min(t0 + x + z - t1, ans); } } else { ans = min(t1 - t0, t0 + x + z - t1); ans = min(t0 + y + z - t1, ans); } cout<<ans<<endl; }