結果

問題 No.126 2基のエレベータ
ユーザー くれちー
提出日時 2017-01-07 16:56:13
言語 C90
(gcc 12.3.0)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 390 bytes
コンパイル時間 235 ms
コンパイル使用メモリ 21,120 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-10 18:31:12
合計ジャッジ時間 1,124 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:7:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    7 |         scanf("%d %d %d", &a, &b, &s);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>
#define min(a, b) a < b ? a : b

int main() {
	int a, b, s;
	scanf("%d %d %d", &a, &b, &s);

	int da = abs(s - a), db = abs(s - b);
	int ans, ans2;

	if (s == 1) ans = da + 1;
	else if (da <= db) ans = da + s;
	else {
		ans = db + s + abs(1 - a);
		ans2 = db + abs(a - s) + a;
		if (a != 0) ans = min(ans, ans2);
	}

	printf("%d\n", ans);
	return 0;
}
0