結果

問題 No.31 悪のミックスジュース
ユーザー aru aruaru aru
提出日時 2020-07-10 23:04:51
言語 Go
(1.21.3)
結果
RE  
実行時間 -
コード長 1,604 bytes
コンパイル時間 10,672 ms
コンパイル使用メモリ 208,552 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-01 22:29:49
合計ジャッジ時間 11,548 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 AC 1 ms
4,376 KB
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 AC 2 ms
4,376 KB
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
権限があれば一括ダウンロードができます

ソースコード

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, S int) int {
	if a > S {
		return a
	}
	return S
}

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

func asub(a, S int) int {
	if a > S {
		return a - S
	}
	return S - 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
}

func main() {
	sc.Split(bufio.ScanWords)
	N, V := getInt(), getInt()
	S := make([]int, N+1)
	c := make([]int, N+1)
	for i := 1; i <= N; i++ {
		c[i] = getInt()
		S[i] = S[i-1] + c[i]
	}

	if V <= N {
		out(S[N])
		return
	}

	V -= N
	x := 1
	for i := 2; i <= N; i++ {
		// out(S[i], x, S[x], i)
		if S[i]*x < S[x]*i {
			x = i
		}
	}

	var dp [21000]int
	// initialize
	for i := 0; i <= min(21000, V); i++ {
		dp[i] = 1 << 60
		if (V-i)%x == 0 {
			dp[i] = (V - i) / x * S[x]
		}
	}
	// dp
	for i := min(20000, V); i >= 0; i-- {
		for j := 1; j < N; j++ {
			dp[i] = min(dp[i], dp[i+j]+S[j])
		}
	}
	out(dp[0] + S[N])
}
0