結果

問題 No.859 路線A、路線B、路線C
ユーザー tokutoku
提出日時 2019-08-09 22:10:00
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,904 bytes
コンパイル時間 1,156 ms
コンパイル使用メモリ 145,120 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-26 18:08:53
合計ジャッジ時間 1,945 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,384 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:69:44: warning: ‘d’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   ll ans = min({ a + b - 1,c + d + 1,x + a + d,x + b + c });
                                      ~~~~~~^~~
main.cpp:69:30: warning: ‘c’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   ll ans = min({ a + b - 1,c + d + 1,x + a + d,x + b + c });
                            ~~^~~

ソースコード

diff #

#include <bits/stdc++.h>


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 30;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;



int main() {

	ll x, y, z;
	cin >> x >> y >> z;

	char sa, sb;
	ll ta, tb;
	cin >> sa >> ta >> sb >> tb;

	if (sa == sb) {
		ll ans = abs(tb - ta);
		if (tb < ta)swap(ta, tb);
		if (sa == 'A') {
			ans = min(ans, y + ta - tb + x);
			ans = min(ans, z + ta - tb + x);
		}
		else if (sa == 'B') {
			ans = min(ans, x + ta - tb + y);
			ans = min(ans, z + ta - tb + y);
		}
		else if (sa == 'C') {
			ans = min(ans, x + ta - tb + z);
			ans = min(ans, y + ta - tb + z);
		}
		cout << ans << endl;
		return 0;
	}

	ll a, b, c, d;

	a = ta;
	b = tb;
	if (sa == 'A')c = x - ta;
	if (sa == 'B')c = y - ta;
	if (sa == 'C')c = z - ta;
	if (sb == 'A')d = x - tb;
	if (sb == 'B')d = y - tb;
	if (sb == 'C')d = z - tb;

	if (sa != 'A'&&sb != 'A') {
		ll ans = min({ a + b - 1,c + d + 1,x + a + d,x + b + c });
		cout << ans << endl;
		return 0;
	}
	if (sa != 'B'&&sb != 'B') {
		ll ans = min({ a + b - 1,c + d + 1,y + a + d,y + b + c });
		cout << ans << endl;
		return 0;
	}
	if (sa != 'C'&&sb != 'C') {
		ll ans = min({ a + b - 1,c + d + 1,z + a + d,z + b + c });
		cout << ans << endl;
		return 0;
	}
	

	


}
0