結果

問題 No.126 2基のエレベータ
ユーザー tyochiaityochiai
提出日時 2015-01-17 08:53:38
言語 Go
(1.22.1)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 617 bytes
コンパイル時間 11,075 ms
コンパイル使用メモリ 244,260 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-01 14:45:18
合計ジャッジ時間 12,029 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 WA -
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 1 ms
5,376 KB
testcase_25 AC 1 ms
5,376 KB
testcase_26 AC 1 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 1 ms
5,376 KB
testcase_29 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"fmt"
	"math"
)

func MinInt(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}

func AbsInt(x int) int {
	return int(math.Abs(float64(x)))
}

func resolve(A, B, S int) int {
	if AbsInt(A-S) <= AbsInt(B-S) {
		// Move A
		return AbsInt(A-S) + S
	}
	// Move B + A
	if A == 0 {
		// goto and upto 1st floor
		return AbsInt(B-S) + S + 1
	}
	// goto 1st floor
	tmp1 := AbsInt(B-S) + (S - 1) + A
	// goto A floor
	tmp2 := AbsInt(B-S) + AbsInt(A-S) + A
	return MinInt(tmp1, tmp2)
}

func main() {
	var A, B, S int

	fmt.Scanf("%d %d %d\n", &A, &B, &S)

	fmt.Println(resolve(A, B, S))
}
0