結果

問題 No.859 路線A、路線B、路線C
ユーザー QCFiumQCFium
提出日時 2019-08-09 22:00:30
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 952 bytes
コンパイル時間 1,417 ms
コンパイル使用メモリ 165,372 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-26 17:53:28
合計ジャッジ時間 2,173 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int64_t rll() {
	long long n;
	scanf("%lld", &n);
	return n;
}

int main() {
	int64_t x[3];
	for (int i = 0; i < 3; i++) x[i] = ri();
	char s1, s2;
	int64_t t1, t2;
	{
		std::string tmp;
		std::cin >> tmp;
		s1 = tmp[0];
		t1 = ri() - 1;
		std::cin >> tmp;
		s2 = tmp[0];
		t2 = ri() - 1;
		
		if (t1 > t2) std::swap(t1, t2), std::swap(s1, s2);
	}
	s1 -= 'A';
	s2 -= 'A';
	int64_t res = 1000000001;
	if (s1 == s2) res = std::min(res, t2 - t1);
	for (int i = 0; i < 3; i++) {
		{
			int64_t cost = 0;
			int64_t pos1;
			if (i == s1) pos1 = t1;
			else pos1 = 0, cost += t1 + 1;
			int64_t pos2;
			if (i == s2) pos2 = t2;
			else pos2 = x[i] - 1, cost += x[s2] - t2;
			cost += pos2 - pos1;
			res = std::min(res, cost);
		}
		res = std::min(res, t1 + t2 + 1);
		res = std::min(res, (x[s1] - t1 - 1) + (x[s2] - t2 - 1) + 1);
	}
	std::cout << res << std::endl;
	
	return 0;
}
0