結果

問題 No.158 奇妙なお使い
ユーザー aru aruaru aru
提出日時 2020-08-26 22:47:52
言語 Go
(1.21.3)
結果
AC  
実行時間 638 ms / 5,000 ms
コード長 2,081 bytes
コンパイル時間 13,033 ms
コンパイル使用メモリ 197,724 KB
実行使用メモリ 179,272 KB
最終ジャッジ日時 2023-08-07 10:26:54
合計ジャッジ時間 16,343 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
90,252 KB
testcase_01 AC 32 ms
90,348 KB
testcase_02 AC 32 ms
90,252 KB
testcase_03 AC 32 ms
90,252 KB
testcase_04 AC 638 ms
145,208 KB
testcase_05 AC 33 ms
90,252 KB
testcase_06 AC 32 ms
90,252 KB
testcase_07 AC 32 ms
90,252 KB
testcase_08 AC 32 ms
90,256 KB
testcase_09 AC 33 ms
90,256 KB
testcase_10 AC 33 ms
90,260 KB
testcase_11 AC 33 ms
90,272 KB
testcase_12 AC 33 ms
90,252 KB
testcase_13 AC 32 ms
90,252 KB
testcase_14 AC 32 ms
90,260 KB
testcase_15 AC 32 ms
90,340 KB
testcase_16 AC 33 ms
90,312 KB
testcase_17 AC 34 ms
90,344 KB
testcase_18 AC 68 ms
95,556 KB
testcase_19 AC 32 ms
90,264 KB
testcase_20 AC 32 ms
90,344 KB
testcase_21 AC 48 ms
108,300 KB
testcase_22 AC 87 ms
179,272 KB
testcase_23 AC 33 ms
90,260 KB
testcase_24 AC 32 ms
90,252 KB
testcase_25 AC 32 ms
90,252 KB
testcase_26 AC 33 ms
90,264 KB
testcase_27 AC 32 ms
90,256 KB
testcase_28 AC 33 ms
90,296 KB
testcase_29 AC 32 ms
90,264 KB
testcase_30 AC 34 ms
92,532 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

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

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

var d0, d1 int
var b, c []int

func calc(a, b []int, din int) ([]int, int) {
	ret := make([]int, 3)
	for i := a[0]; i >= 0; i-- {
		for j := a[1]; j >= 0; j-- {
			d := din - i*1000 - j*100
			// out(d, din, i, j, a)
			if d >= 0 && d <= a[2] {
				ret[0] = a[0] - i + b[0]
				ret[1] = a[1] - j + b[1]
				ret[2] = a[2] - d + b[2]
				return ret, 1
			}
		}
	}
	return ret, -1
}

var memo [11][101][10001]int

func rec(a []int, s string) int {
	// out("rev", a, s)
	if memo[a[0]][a[1]][a[2]] != -1 {
		return memo[a[0]][a[1]][a[2]]
	}

	n, m := 0, 0

	ret, ok := calc(a, b, d0)
	if ok == 1 {
		n = rec(ret, s+"B") + 1
		// out("---->", n)
	}
	ret, ok = calc(a, c, d1)
	if ok == 1 {
		m = rec(ret, s+"C") + 1
		// out("---->", m)
	}
	memo[a[0]][a[1]][a[2]] = max(n, m)
	return max(n, m)
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)
	a := getInts(3)
	d0 = getInt()
	b = getInts(3)
	d1 = getInt()
	c = getInts(3)

	for i := 0; i < 11; i++ {
		for j := 0; j < 101; j++ {
			for k := 0; k < 10001; k++ {
				memo[i][j][k] = -1
			}

		}
	}

	ret := rec(a, "")
	out(ret)
}
0