結果
問題 | No.859 路線A、路線B、路線C |
ユーザー | koyopro |
提出日時 | 2020-01-19 01:30:04 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 2 ms / 1,000 ms |
コード長 | 1,724 bytes |
コンパイル時間 | 1,203 ms |
コンパイル使用メモリ | 154,480 KB |
実行使用メモリ | 4,380 KB |
最終ジャッジ日時 | 2023-09-11 01:08:30 |
合計ジャッジ時間 | 2,588 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,380 KB |
testcase_01 | AC | 2 ms
4,376 KB |
testcase_02 | AC | 2 ms
4,376 KB |
testcase_03 | AC | 1 ms
4,380 KB |
testcase_04 | AC | 1 ms
4,376 KB |
testcase_05 | AC | 2 ms
4,380 KB |
testcase_06 | AC | 1 ms
4,376 KB |
testcase_07 | AC | 1 ms
4,380 KB |
testcase_08 | AC | 1 ms
4,380 KB |
testcase_09 | AC | 2 ms
4,376 KB |
testcase_10 | AC | 2 ms
4,380 KB |
testcase_11 | AC | 2 ms
4,380 KB |
testcase_12 | AC | 2 ms
4,380 KB |
testcase_13 | AC | 1 ms
4,380 KB |
testcase_14 | AC | 1 ms
4,376 KB |
ソースコード
#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; }