結果

問題 No.31 悪のミックスジュース
ユーザー aru aruaru aru
提出日時 2020-07-10 23:05:27
言語 Go
(1.22.1)
結果
WA  
実行時間 -
コード長 1,604 bytes
コンパイル時間 15,136 ms
コンパイル使用メモリ 226,828 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-19 23:24:52
合計ジャッジ時間 10,897 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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(20020, 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