結果

問題 No.859 路線A、路線B、路線C
ユーザー MarcusAureliusAntoninusMarcusAureliusAntoninus
提出日時 2019-08-09 21:56:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,344 bytes
コンパイル時間 2,197 ms
コンパイル使用メモリ 209,128 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-09-26 17:51:15
合計ジャッジ時間 4,841 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

int main()
{
	int64_t x[3];
	for (int i{}; i < 3; i++) scanf("%lld", x + i);
	using vpi = std::vector<std::pair<int, int64_t>>;
	using vvpi = std::vector<vpi>;
	vvpi edges(8);
	for (int i{}; i < 3; i++)
		for (int j{}; j < 2; j++)
		{
			int diff{(i + j) % 3};
			edges[1 + i].push_back({1 + diff, 1ll});
			edges[4 + i].push_back({4 + diff, 1ll});
		}
	
	for (int i{1}; i <= 3; i++)
	{
		edges[i].push_back({i + 3, x[i] - 1});
		edges[i + 3].push_back({i, x[i] - 1});
	}
	char S[2];
	int64_t index[2];
	for (int i{}; i < 2; i++)
		scanf(" %c%lld", S + i, index + i);
	edges[0].push_back({1 + S[0] - 'A', index[0] - 1});
	edges[0].push_back({4 + S[0] - 'A', x[S[0] - 'A'] - index[0]});
	edges[1 + S[1] - 'A'].push_back({7, index[1] - 1});
	edges[4 + S[1] - 'A'].push_back({7, x[S[1] - 'A'] - index[1]});

	using P = std::pair<int64_t, int>;
	std::priority_queue<P, std::vector<P>, std::greater<P>> dij;
	std::vector<int64_t> dist(8, 1ll << 60);
	dij.push({0, 0});
	dist[0] = 0;
	while (!dij.empty())
	{
		auto now{dij.top()};
		dij.pop();
		if (now.first > dist[now.second]) continue;
		for (auto& e: edges[now.second])
		{
			P next{now.first + e.second, e.first};
			if (next.first >= dist[next.second]) continue;
			dist[next.second] = next.first;
			dij.push(next);
		}
	}
	printf("%lld\n", dist[7]);

	return 0;
}
0