結果

問題 No.859 路線A、路線B、路線C
ユーザー MarcusAureliusAntoninusMarcusAureliusAntoninus
提出日時 2019-08-09 22:11:14
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,434 bytes
コンパイル時間 2,357 ms
コンパイル使用メモリ 202,952 KB
最終ジャッジ日時 2025-01-07 11:21:56
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:6:45: warning: format ‘%lld’ expects argument of type ‘long long int*’, but argument 2 has type ‘int64_t*’ {aka ‘long int*’} [-Wformat=]
    6 |         for (int i{}; i < 3; i++) scanf("%lld", x + i);
      |                                          ~~~^   ~~~~~
      |                                             |     |
      |                                             |     int64_t* {aka long int*}
      |                                             long long int*
      |                                          %ld
main.cpp:27:30: warning: format ‘%lld’ expects argument of type ‘long long int*’, but argument 3 has type ‘int64_t*’ {aka ‘long int*’} [-Wformat=]
   27 |                 scanf(" %c%lld", S + i, index + i);
      |                           ~~~^          ~~~~~~~~~
      |                              |                |
      |                              long long int*   int64_t* {aka long int*}
      |                           %ld
main.cpp:52:20: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 2 has type ‘__gnu_cxx::__alloc_traits<std::allocator<long int>, long int>::value_type’ {aka ‘long int’} [-Wformat=]
   52 |         printf("%lld\n", dist[7]);
      |                 ~~~^
      |                    |
      |                    long long int
      |                 %ld
main.cpp:6:40: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    6 |         for (int i{}; i < 3; i++) scanf("%lld", x + i);
      |                                   ~~~~~^~~~~~~~~~~~~~~
main.cpp:27:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   27 |                 scanf(" %c%lld", S + i, index + i);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>

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

	if (S[0] == S[1]) edges[0].push_back({std::abs(index[1] - index[0]), 7});

	std::priority_queue<pi, std::vector<pi>, std::greater<pi>> 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])
		{
			pi next{now.first + e.first, e.second};
			if (next.first >= dist[next.second]) continue;
			dist[next.second] = next.first;
			dij.push(next);
		}
	}
	printf("%lld\n", dist[7]);

	return 0;
}
0