結果

問題 No.859 路線A、路線B、路線C
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2019-08-09 21:47:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,594 bytes
コンパイル時間 3,180 ms
コンパイル使用メモリ 210,388 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-26 17:38:59
合計ジャッジ時間 3,417 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 2 ms
4,380 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/














int x, y, z;
char s0; int t0;
char s1; int t1;
//---------------------------------------------------------------------------------------------------
map<char, int> ma;
map<string, map<string, int>> E;
string enc(char c, int i) {
	return to_string(i) + c;
}
void add(char c1, int i1, char c2, char i2, int len) {
	if (c1 == c2 and i1 == i2) return;
	E[enc(c1, i1)][enc(c2, i2)] = len;
	E[enc(c2, i2)][enc(c1, i1)] = len;
}
void _main() {
	cin >> x >> y >> z;
	cin >> s0 >> t0 >> s1 >> t1;
	ma['A'] = x;
	ma['B'] = y;
	ma['C'] = z;

	add('A', 1, 'B', 1, 1);
	add('A', 1, 'C', 1, 1);
	add('B', 1, 'C', 1, 1);

	add('A', x, 'B', y, 1);
	add('A', x, 'C', z, 1);
	add('B', y, 'C', z, 1);

	add('A', 1, 'A', x, x - 1);
	add('B', 1, 'B', y, y - 1);
	add('C', 1, 'C', z, z - 1);

	add(s0, 1, s0, t0, t0 - 1);
	add(s0, ma[s0], s0, t0, ma[s0] - t0);

	add(s1, 1, s1, t1, t1 - 1);
	add(s1, ma[s1], s1, t1, ma[s1] - t1);

	if (s0 == s1) add(s0, t0, s1, t1, abs(t0 - t1));

	vector<string> nodes;
	fore(p, E) nodes.push_back(p.first);

	map<string, map<string, ll>> d;
	fore(from, nodes) fore(to, nodes) d[from][to] = infl;
	fore(node, nodes) d[node][node] = 0;
	fore(cu, nodes) fore(p, E[cu]) d[cu][p.first] = p.second; 
	fore(k, nodes) fore(i, nodes) fore(j, nodes) chmin(d[i][j], d[i][k] + d[k][j]);

	ll ans = d[enc(s0, t0)][enc(s1, t1)];
	cout << ans << endl;
}
0