結果
問題 |
No.281 門松と魔法(1)
|
ユーザー |
![]() |
提出日時 | 2015-09-19 20:57:15 |
言語 | Go1.4 (1.4.2) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,962 bytes |
コンパイル時間 | 260 ms |
コンパイル使用メモリ | 32,696 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-11-25 00:35:35 |
合計ジャッジ時間 | 1,702 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 55 WA * 2 |
ソースコード
package main import ( "bufio" "fmt" "os" "strconv" ) func main() { solve281() } func solve281() { //var d, a, b, c int d := nextInt() a := nextInt() b := nextInt() c := nextInt() 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 } var s = bufio.NewScanner(os.Stdin) func next() string { s.Split(bufio.ScanWords) s.Scan() return s.Text() } func nextInt() int { i, e := strconv.Atoi(next()) if e != nil { panic(e) } return i }