結果
問題 |
No.859 路線A、路線B、路線C
|
ユーザー |
![]() |
提出日時 | 2020-04-13 19:02:56 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 1,000 ms |
コード長 | 2,750 bytes |
コンパイル時間 | 1,538 ms |
コンパイル使用メモリ | 137,872 KB |
最終ジャッジ日時 | 2025-01-09 18:10:36 |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 |
ソースコード
#include <algorithm> #include <cmath> #include <complex> #include <iostream> #include <map> #include <queue> #include <set> #include <vector> #include <functional> #include <cstring> #include <regex> #include <random> #include <cassert> #include <stack> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repr(i, s, n) for (int i = (s); i < (int)(n); i++) #define revrep(i, n) for (int i = (n) - 1; i >= 0; i--) #define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--) #define debug(x) cerr << #x << ": " << x << "\n" #define popcnt(x) __builtin_popcount(x) using ll = long long; using P = pair<int, int>; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template<class T> istream& operator >>(istream &is, vector<T> &v) { for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i); return is; } template<class T, class U> ostream& operator <<(ostream &os, pair<T, U> p) { cout << '(' << p.first << ", " << p.second << ')'; return os; } template<class T> void print(const vector<T> &v, const string &delimiter) { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; } template<class T> void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); } const ll INF = 1e18; const int MAX_V = 8; vector<vector<ll>> d(MAX_V, vector<ll>(MAX_V, INF)); int V = 8; void warshall_floyd() { for (int k = 0; k < V; k++) { for (int i = 0; i < V; i++) { for (int j = 0; j < V; j++) { d[i][j] = min(d[i][j], d[i][k] + d[k][j]); } } } } int main() { vector<ll> len(3); cin >> len; auto add_edge = [&](int u, int v, ll w){ d[u][v] = w; d[v][u] = w; }; add_edge(0, 1, len[0] - 1); add_edge(0, 2, 1); add_edge(0, 4, 1); add_edge(1, 3, 1); add_edge(1, 5, 1); add_edge(2, 3, len[1] - 1); add_edge(2, 4, 1); add_edge(3, 5, 1); add_edge(4, 5, len[2] - 1); char s1, s2; int num1, num2; cin >> s1 >> num1 >> s2 >> num2; int line1 = s1 - 'A', line2 = s2 - 'A'; if (line1 == line2) { if (num1 > num2) swap(num1, num2); add_edge(line1 * 2, 6, num1 - 1); add_edge(line2 * 2 + 1, 7, len[line1] - num2); add_edge(6, 7, num2 - num1); } else { add_edge(line1 * 2, 6, num1 - 1); add_edge(line1 * 2 + 1, 6, len[line1] - num1); add_edge(line2 * 2, 7, num2 - 1); add_edge(line2 * 2 + 1, 7, len[line2] - num2); } warshall_floyd(); cout << d[6][7] << endl; }