結果

問題 No.859 路線A、路線B、路線C
ユーザー kwm_tkwm_t
提出日時 2023-05-01 17:15:54
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,053 bytes
コンパイル時間 2,102 ms
コンパイル使用メモリ 203,188 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-12 22:50:44
合計ジャッジ時間 3,589 ms
ジャッジサーバーID
(参考情報)
judge13 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
//const int INF = 1e9;
const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
#define P pair<int,int>
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	long long x, y, z; cin >> x >> y >> z;
	char s0, s1;
	int t0, t1;
	cin >> s0 >> t0; t0--;
	cin >> s1 >> t1; t1--;
	vector d(8, vector<long long>(8, LINF));
	rep(i, 8)d[i][i] = 0;
	rep(i, 3)rep(j, 3)if (i != j) {
		d[i][j] = 1;
		d[i + 3][j + 3] = 1;
	}
	d[0][3] = x - 1;
	d[3][0] = x - 1;
	d[1][4] = y - 1;
	d[4][1] = y - 1;
	d[2][5] = z - 1;
	d[5][2] = z - 1;
	if ('A' == s0) {
		d[0][6] = t0;
		d[6][0] = t0;
		d[3][6] = x - 1 - t0;
		d[6][3] = x - 1 - t0;
	}
	else if ('B' == s0) {
		d[1][6] = t0;
		d[6][1] = t0;
		d[4][6] = y - 1 - t0;
		d[6][4] = y - 1 - t0;
	}
	else {
		d[2][6] = t0;
		d[6][2] = t0;
		d[5][6] = z - 1 - t0;
		d[6][5] = z - 1 - t0;
	}
	if ('A' == s1) {
		d[0][7] = t1;
		d[7][0] = t1;
		d[3][7] = x - 1 - t1;
		d[6][7] = x - 1 - t1;
	}
	else if ('B' == s1) {
		d[1][7] = t1;
		d[7][1] = t1;
		d[4][7] = y - 1 - t1;
		d[7][4] = y - 1 - t1;
	}
	else {
		d[2][7] = t1;
		d[7][2] = t1;
		d[5][7] = z - 1 - t1;
		d[7][5] = z - 1 - t1;
	}
	// warshall_floyd
	rep(k, 8) rep(i, 8)rep(j, 8) {
		d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
	}
	long long ans = d[6][7];
	if (s0 == s1)chmin(ans, abs(t1 - t0));
	cout << ans << endl;
	return 0;
}
0