結果

問題 No.281 門松と魔法(1)
ユーザー fmhrfmhr
提出日時 2015-09-19 20:51:16
言語 Go
(1.22.1)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,690 bytes
コンパイル時間 11,164 ms
コンパイル使用メモリ 225,792 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-24 11:51:31
合計ジャッジ時間 12,583 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 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 1 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 2 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 2 ms
5,376 KB
testcase_21 AC 2 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 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 1 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 AC 1 ms
5,376 KB
testcase_38 AC 1 ms
5,376 KB
testcase_39 AC 2 ms
5,376 KB
testcase_40 AC 1 ms
5,376 KB
testcase_41 AC 1 ms
5,376 KB
testcase_42 AC 1 ms
5,376 KB
testcase_43 AC 1 ms
5,376 KB
testcase_44 AC 2 ms
5,376 KB
testcase_45 WA -
testcase_46 AC 1 ms
5,376 KB
testcase_47 WA -
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 2 ms
5,376 KB
testcase_53 AC 1 ms
5,376 KB
testcase_54 AC 1 ms
5,376 KB
testcase_55 AC 1 ms
5,376 KB
testcase_56 AC 2 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)
	if isKadomatsu(a, b, c) {
		fmt.Println("0")
		return
	} else if d == 0 {
		// d == 0 のとき, なにも操作できない
		fmt.Println("-1")
		return
	}

	var cnt1, cnt2 int

	// 真ん中を下げる用意
	b1 := b
	// 左右のどちらかが0だと不成立
	if a == 0 || c == 0 {
		cnt1 = -1
	} else {
		// 左右a,cが同値のときは先に一方(a)を下げておく
		aa := a
		if a == c {
			cnt1++
			aa = a - d
		}

		foo := ((b - min(aa, c)) / d) + 1
		if foo > 0 {
			cnt1 += foo
			b1 = max(0, b1-d*foo)
		}

		if isKadomatsu(aa, b1, c) == false {
			cnt1 = -1
		}
	}

	// 左右を下げる
	if b == 0 {
		cnt2 = -1
	} else {
		a1 := a
		if a > 0 {
			bar := ((a - b) / d) + 1
			if bar > 0 {
				cnt2 = bar
				a1 = max(0, a1-d*bar)
			}
		}
		c1 := c
		if c > 0 {
			foobar := ((c - b) / d) + 1
			if foobar > 0 {
				cnt2 += foobar
				c1 = max(0, c1-d*foobar)
			}
		}
		ax := a
		if a == c && cnt2 >= 0 {
			ax = max(0, ax-d)
			cnt2++
		}
		if isKadomatsu(ax, b, c1) == false {
			cnt2 = -1
		}
	}

	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))
	}
	//fmt.Println(cnt1, cnt2)
	//fmt.Println(a,b1,c)
	return
}

// 門松判定器
func isKadomatsu(a, b, c int) bool {
	if a < b && b > c && a != c {
		return true
	} else if a > b && b < c && a != c {
		return true
	}
	return false
}

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