結果

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

テストケース

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

ソースコード

diff #

package main

import (
	"bufio"
	"fmt"
	"math"
	"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]
	}
	sum := S[N]
	if V <= N {
		out(sum)
		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(20200, V); i++ {
		dp[i] = math.MaxUint64 / 8
		if (V-i)%x == 0 {
			dp[i] = (V - i) / x * S[x]
		}
	}
	// dp
	for i := min(20000, V); i >= 0; i-- {
		for j := 0; j < N; j++ {
			dp[i] = min(dp[i], dp[i+j]+S[j])
		}
	}
	out(dp[0] + S[N])
}
0