結果

問題 No.126 2基のエレベータ
ユーザー hanorver
提出日時 2016-05-25 21:25:27
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 394 bytes
コンパイル時間 480 ms
コンパイル使用メモリ 64,824 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-10 18:30:10
合計ジャッジ時間 1,372 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<cstdlib>

int main() {
	int a, b, s;

	std::cin >> a >> b >> s;

	int dist_a = std::abs(a - s),
		dist_b = std::abs(b - s);
	
	int ans;
	if (dist_a <= dist_b || dist_a == dist_b || s == 1) {
		ans = dist_a + s;
	} else {
		ans = dist_b;
		if (dist_a < s - 1) ans += dist_a;
		else ans += s - 1;
		if (a == 0) ans+=2;
		ans += a;
	}

	std::cout << ans << std::endl;
}
0