結果

問題 No.126 2基のエレベータ
ユーザー くれちー
提出日時 2017-01-07 16:41:35
言語 C90
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 388 bytes
コンパイル時間 133 ms
コンパイル使用メモリ 21,248 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-12-17 16:19:56
合計ジャッジ時間 1,058 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25 WA * 2
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 = 0, ans2 = 0;

	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;
		ans = min(ans, ans2);
	}

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