結果
| 問題 |
No.859 路線A、路線B、路線C
|
| コンテスト | |
| ユーザー |
sprng_wl
|
| 提出日時 | 2019-08-09 22:51:29 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 1,000 ms |
| コード長 | 1,442 bytes |
| コンパイル時間 | 2,493 ms |
| コンパイル使用メモリ | 170,340 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-19 14:58:52 |
| 合計ジャッジ時間 | 3,092 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 |
ソースコード
#include <bits/stdc++.h>
#define Int int64_t
using namespace std;
template <typename T>
struct edge {
int to;
T cost;
edge(int t, T c) : to(t), cost(c) {}
};
template <typename T>
void dijkstra(const vector<vector< edge<T> >>& G, vector<T>& d, int s) {
priority_queue<pair<T, int>, vector< pair<T, int> >, greater< pair<T, int> >> que;
d[s] = 0;
que.emplace(0, s);
while (!que.empty()) {
auto p = que.top();
que.pop();
int u = p.second;
if (d[u] < p.first) { continue; }
for (auto e : G[u]) {
if (d[e.to] <= d[u] + e.cost) { continue; }
d[e.to] = d[u] + e.cost;
que.emplace(d[e.to], e.to);
}
}
}
int main() {
const Int INF = 1e18;
vector<vector< edge<Int> >> g(7);
for (int i = 1; i <= 6; ++i) {
for (int j = 1; j <= 6; ++j) {
if (i == j || (i % 2 != j % 2)) { continue; }
g[i].emplace_back(j, 1);
}
}
Int x[3];
for (int i = 0; i < 3; ++i) {
cin >> x[i];
int idx = i * 2 + 1;
g[idx].emplace_back(idx + 1, x[i] - 1);
g[idx + 1].emplace_back(idx, x[i] - 1);
}
char s0, s1;
Int t0, t1;
cin >> s0 >> t0;
cin >> s1 >> t1;
int idx = (int)(s0 - 'A') * 2 + 1;
g[0].emplace_back(idx, t0 - 1);
g[0].emplace_back(idx + 1, x[int(s0 - 'A')] - t0);
vector<Int> d(7, INF);
dijkstra(g, d, 0);
idx = (int)(s1 - 'A') * 2 + 1;
Int ans = min(d[idx] + (t1 - 1), d[idx + 1] + (x[int(s1 - 'A')] - t1));
if (s0 == s1) {
ans = min(ans, abs(t0 - t1));
}
cout << ans << endl;
return 0;
}
sprng_wl