結果

問題 No.859 路線A、路線B、路線C
ユーザー leaf_1415leaf_1415
提出日時 2019-08-09 22:15:29
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 833 bytes
コンパイル時間 1,141 ms
コンパイル使用メモリ 51,700 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-26 18:14:41
合計ジャッジ時間 1,985 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#define llint long long

using namespace std;

llint x, y, z;
char Sc, Tc;
llint Sid, Tid;

int main(void)
{
	cin >> x >> y >> z;
	cin >> Sc >> Sid;
	cin >> Tc >> Tid;
	
	if(Sc == Tc){
		if(Sid > Tid) swap(Sid, Tid);
		if(Sc == 'C') swap(x, z);
		if(Sc == 'B'){
			cout << min(Tid-Sid, Sid+(y-Tid)+min(x, z)) << endl;
			return 0;
		}
		cout << min(Tid-Sid, Sid+(x-Tid)+min(y, z)) << endl;
		return 0;
	}
	else{
		if(Sc == 'B'){
			swap(Sc, Tc);
			swap(Sid, Tid);
		}
		if(Sc == 'C'){
			swap(x, z);
		}
		
		if(Tc == 'B'){
			llint ans = min(Sid+Tid-1, (x-Sid)+(y-Tid)+1);
			ans = min(ans, min((x-Sid)+z+Tid, Sid+z+(y-Tid)));
			cout << ans << endl;
			return 0;
		}
		llint ans =  min(Sid+Tid-1, min(Sid+y+(z-Tid), (x-Sid)+(z-Tid)+1));
		ans = min(ans, (x-Sid)+y+Tid);
		cout << ans << endl;
	}
	
	return 0;
}
0