結果

問題 No.281 門松と魔法(1)
ユーザー fmhrfmhr
提出日時 2015-09-19 18:51:54
言語 Go
(1.22.1)
結果
RE  
実行時間 -
コード長 1,130 bytes
コンパイル時間 12,751 ms
コンパイル使用メモリ 222,988 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-24 11:48:06
合計ジャッジ時間 14,019 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,816 KB
testcase_02 AC 1 ms
6,812 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 1 ms
6,940 KB
testcase_14 AC 1 ms
6,940 KB
testcase_15 AC 1 ms
6,944 KB
testcase_16 AC 1 ms
6,940 KB
testcase_17 AC 1 ms
6,944 KB
testcase_18 AC 1 ms
6,940 KB
testcase_19 AC 1 ms
6,944 KB
testcase_20 AC 1 ms
6,940 KB
testcase_21 AC 1 ms
6,940 KB
testcase_22 AC 1 ms
6,944 KB
testcase_23 AC 1 ms
6,940 KB
testcase_24 AC 1 ms
6,944 KB
testcase_25 AC 1 ms
6,944 KB
testcase_26 AC 2 ms
6,944 KB
testcase_27 AC 1 ms
6,940 KB
testcase_28 AC 1 ms
6,940 KB
testcase_29 AC 1 ms
6,940 KB
testcase_30 AC 1 ms
6,944 KB
testcase_31 RE -
testcase_32 RE -
testcase_33 AC 1 ms
6,944 KB
testcase_34 AC 1 ms
6,944 KB
testcase_35 AC 1 ms
6,944 KB
testcase_36 AC 1 ms
6,940 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 1 ms
6,944 KB
testcase_43 RE -
testcase_44 AC 1 ms
6,944 KB
testcase_45 AC 1 ms
6,940 KB
testcase_46 AC 1 ms
6,940 KB
testcase_47 AC 1 ms
6,940 KB
testcase_48 AC 1 ms
6,940 KB
testcase_49 AC 1 ms
6,940 KB
testcase_50 RE -
testcase_51 AC 1 ms
6,944 KB
testcase_52 AC 1 ms
6,944 KB
testcase_53 AC 1 ms
6,944 KB
testcase_54 RE -
testcase_55 AC 1 ms
6,944 KB
testcase_56 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"fmt"
)

func main() {
	solve281()
}

func solve281() {
	var d, a, b, c int
	fmt.Scan(&d, &a, &b, &c)
	var cnt1, cnt2 int
	b1 := b
	if a == 0 || c == 0 {
		cnt1 = -1
	}else{
		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
		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
		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