結果

問題 No.126 2基のエレベータ
ユーザー TANIGUCHI KousukeTANIGUCHI Kousuke
提出日時 2015-07-14 11:19:44
言語 Ruby
(3.3.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 319 bytes
コンパイル時間 68 ms
コンパイル使用メモリ 11,452 KB
実行使用メモリ 15,332 KB
最終ジャッジ日時 2023-08-22 16:12:28
合計ジャッジ時間 4,742 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
15,152 KB
testcase_01 AC 83 ms
15,060 KB
testcase_02 AC 81 ms
15,268 KB
testcase_03 AC 81 ms
15,140 KB
testcase_04 AC 81 ms
15,072 KB
testcase_05 AC 85 ms
15,124 KB
testcase_06 AC 82 ms
15,172 KB
testcase_07 AC 83 ms
15,020 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 80 ms
15,024 KB
testcase_11 AC 81 ms
15,264 KB
testcase_12 AC 81 ms
15,036 KB
testcase_13 AC 81 ms
15,068 KB
testcase_14 AC 81 ms
15,140 KB
testcase_15 AC 82 ms
15,264 KB
testcase_16 AC 84 ms
15,164 KB
testcase_17 AC 80 ms
15,240 KB
testcase_18 AC 81 ms
15,112 KB
testcase_19 AC 81 ms
15,300 KB
testcase_20 AC 81 ms
15,104 KB
testcase_21 AC 81 ms
15,264 KB
testcase_22 AC 81 ms
15,144 KB
testcase_23 AC 81 ms
15,152 KB
testcase_24 AC 81 ms
15,028 KB
testcase_25 AC 82 ms
15,320 KB
testcase_26 AC 81 ms
15,136 KB
testcase_27 AC 80 ms
15,028 KB
testcase_28 AC 80 ms
15,296 KB
testcase_29 AC 80 ms
15,120 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def solve(s,a,b)
  if s == 0
    0
  elsif s == 1
    (s - a).abs + 1
  elsif (s - a).abs < (s - b).abs
    (s - a).abs + s
  else
    candiate = [(s-b).abs + (s-1).abs + (a - 1).abs + 1]
    candiate.push((s-b).abs + (s-a).abs + a) if a > 0 
    candiate.min
  end
end

a,b,s = gets.split.map(&:to_i)
puts solve(s,a,b)
0