結果
問題 | No.859 路線A、路線B、路線C |
ユーザー | gratan_mogmog |
提出日時 | 2019-08-09 21:48:21 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 2 ms / 1,000 ms |
コード長 | 2,616 bytes |
コンパイル時間 | 1,562 ms |
コンパイル使用メモリ | 178,104 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-19 11:36:29 |
合計ジャッジ時間 | 2,135 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,376 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 2 ms
5,376 KB |
testcase_12 | AC | 2 ms
5,376 KB |
testcase_13 | AC | 2 ms
5,376 KB |
testcase_14 | AC | 2 ms
5,376 KB |
ソースコード
#include <bits/stdc++.h> #include <map> #include <set> #include <vector> #include <algorithm> #include <iostream> #include <bitset> #include <cassert> #include <queue> #include <stack> #include <iomanip> #include <math.h> #include <time.h> using namespace std; #define rep(i, n) for (ll i = 0; i < (ll)n; i++) #define repf(i, a, b) for (ll i = (ll)a; i < (ll)b; i++) #define repr(i, a, b) for (ll i = (ll)a; i > (ll)b; i--) #define all(v) (v).begin(), (v).end() #define mp(a, b) make_pair(a, b) #define pb(x) push_back(x) #define eb(x) emplace_back(x) #define F first #define S second typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<ld, ld> pdd; typedef vector<ll> vll; typedef vector<vll> vvll; typedef vector<int> vii; typedef vector<vii> vvii; const ll mod = 1e9 + 7; const int infi = 1147483600; const ll infl = 1e17; const char ENDL = '\n'; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll x, y, z; cin >> x >> y >> z; char ss, gs; ll st, gt; cin >> ss >> st >> gs >> gt; vll dist(10, infl); vvll edges(10, vll(10, infl)); edges[2][3] = edges[3][2] = x-1; edges[4][5] = edges[5][4] = y - 1; edges[6][7] = edges[7][6] = z - 1; edges[0][2] = edges[0][4] = edges[0][6] = 0; edges[1][3] = edges[1][5] = edges[1][7] = 0; edges[2][0] = edges[4][0] = edges[6][0] = edges[3][1] = edges[5][1] = edges[7][1] = 1; if (ss == 'A') { edges[2][8] = edges[8][2] = st - 1; edges[3][8] = edges[8][3] = x - st; } if (ss == 'B') { edges[4][8] = edges[8][4] = st - 1; edges[5][8] = edges[8][5] = y - st; } if (ss == 'C') { edges[6][8] = edges[8][6] = st - 1; edges[7][8] = edges[8][7] = z - st; } if (gs == 'A') { edges[2][9] = edges[9][2] = gt - 1; edges[3][9] = edges[9][3] = x - gt; } if (gs == 'B') { edges[4][9] = edges[9][4] = gt - 1; edges[5][9] = edges[9][5] = y - gt; } if (gs == 'C') { edges[6][9] = edges[9][6] = gt - 1; edges[7][9] = edges[9][7] = z - gt; } if (ss==gs){ edges[8][9] = edges[9][8] = abs(st - gt); } dist[8] = 0; set<ll> check; check.insert(8); while (!(check.empty())){ ll now = *check.begin(); check.erase(now); rep(nex,10){ if (dist[nex]>dist[now]+edges[now][nex]){ dist[nex] = dist[now] + edges[now][nex]; check.insert(nex); } } } cout << dist[9] << ENDL; }