結果

問題 No.859 路線A、路線B、路線C
ユーザー bal4ubal4u
提出日時 2019-08-10 07:51:21
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 1 ms / 1,000 ms
コード長 1,088 bytes
コンパイル時間 925 ms
コンパイル使用メモリ 29,332 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-26 23:13:07
合計ジャッジ時間 1,716 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

// yukicoder 859 路線A、路線B、路線C
// 2019.8.10 bal4u

#include <stdio.h>

typedef long long ll;

inline static ll MIN(ll a, ll b) { return a <= b? a: b; }

ll solve0(int s, int t, int *w) {
	ll a = MIN(w[1], w[2]);
	if (s < t) return MIN(t-s, s+w[0]-t + a);
	return MIN(s-t, t+w[0]-s + a);
}
	
ll solve1(int s, int t, int *w) {
	ll a, ans = s+t-1;
	if ((a = (ll)w[0]-s + w[1]-t + 1) < ans) ans = a;
	if ((a = (ll)s + w[1]-t + w[2]) < ans) ans = a;
	if ((a = (ll)w[0]-s + w[2] + t) < ans) ans = a;
	return ans;
}
	
char f[3];
int main()
{
	int i, j, w[3], t[2], a[3];
	char s[2][5];
	
	for (i = 0; i < 3; i++) scanf("%d", w+i);
	for (i = 0; i < 2; i++) {
		scanf("%s%d", s[i], t+i);
		f[s[i][0]-'A'] |= 1 << i;
	}
	for (i = 0; i < 3; i++) {
		if (f[i] == 3) {
			a[0] = w[i], a[1] = w[(i+1)%3], a[2] = w[(i+2)%3];
			printf("%lld\n", solve0(t[0], t[1], a));
			return 0;
		}
		if (f[i] == 1) for (j = 0; j < 3; j++) if (f[j] == 2) {
			a[0] = w[i], a[1] = w[j], a[2] = !f[0]? w[0]:(!f[1]? w[1]: w[2]);
			printf("%lld\n", solve1(t[0], t[1], a));
			return 0;
		}
	}
	return 0;
}
0