結果

問題 No.281 門松と魔法(1)
ユーザー fmhrfmhr
提出日時 2015-09-19 19:04:21
言語 Go
(1.22.1)
結果
WA  
実行時間 -
コード長 1,364 bytes
コンパイル時間 10,036 ms
コンパイル使用メモリ 241,208 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-24 11:48:39
合計ジャッジ時間 11,421 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 2 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 2 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 1 ms
5,376 KB
testcase_28 AC 1 ms
5,376 KB
testcase_29 AC 1 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 1 ms
5,376 KB
testcase_32 AC 1 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 1 ms
5,376 KB
testcase_35 AC 1 ms
5,376 KB
testcase_36 AC 1 ms
5,376 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 1 ms
5,376 KB
testcase_43 WA -
testcase_44 AC 1 ms
5,376 KB
testcase_45 AC 2 ms
5,376 KB
testcase_46 AC 1 ms
5,376 KB
testcase_47 AC 1 ms
5,376 KB
testcase_48 AC 1 ms
5,376 KB
testcase_49 AC 1 ms
5,376 KB
testcase_50 AC 1 ms
5,376 KB
testcase_51 AC 1 ms
5,376 KB
testcase_52 AC 1 ms
5,376 KB
testcase_53 AC 1 ms
5,376 KB
testcase_54 WA -
testcase_55 AC 1 ms
5,376 KB
testcase_56 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"fmt"
)

func main() {
	solve281()
}

func solve281() {
	var d, a, b, c int
	fmt.Scan(&d, &a, &b, &c)
	/// d==0 のときなにもできない
	if d==0 {
		if a>b&&c>b {
			fmt.Println("0")
		}else if a<b&&c<b {
			fmt.Println("0")
		}else {
			fmt.Println("-1")
		}
		return
	}
	var cnt1, cnt2 int
	b1 := b
	if a == 0 || c == 0 {
		cnt1 = -1
	}else{
		if d>0{
			foo := ((b-min(a, c))/d)-1
			if foo>0{
				cnt1+=foo
				b1 = max(0, b1-d*foo)
			}
		}
		for a <= b1 || c <= b1 {
			cnt1++
			b1 = max(0, b1-d)
			if b1 == 0 {
				break
			}
		}
	}
	
	if b==0{
		cnt2 = -1
	}else{
		a1 := a
		if d>0{
			bar := ((a-b)/d)-1
			if bar >0 {
				cnt2 = bar
				a1 = max(0, a1-d*bar)	
			}
		}
		for a1 >= b {
			cnt2++
			a1 = max(0, a1-d)
			if a1 == 0 {
				break
			}
		}
		c1 := c
		if d>0{
			foobar := ((c-b)/d)-1
			if foobar>0{
				cnt2+=foobar
				c1 = max(0, c1-d*foobar)
			}
		}
		for c1 >= b {
			cnt2++
			c1 = max(0, c1-d)
			if c1 == 0 {
				break
			}
		}
		if a1 == c1 {
			cnt2 = -1
		}
	}

	//fmt.Println(cnt1, cnt2)
	if cnt1 == -1 && cnt2 == -1 {
		fmt.Println("-1")
	} else if cnt1 == -1 {
		fmt.Println(cnt2)
	} else if cnt2 == -1 {
		fmt.Println(cnt1)
	} else {
		fmt.Println(min(cnt1, cnt2))
	}

}

func max(a, b int) int {
	if a < b {
		a = b
	}
	return a
}

func min(a, b int) int {
	if a > b {
		a = b
	}
	return a
}
0