結果

問題 No.31 悪のミックスジュース
ユーザー aru aruaru aru
提出日時 2020-07-10 23:20:01
言語 Go
(1.22.1)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 1,600 bytes
コンパイル時間 11,906 ms
コンパイル使用メモリ 234,228 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-19 23:48:59
合計ジャッジ時間 12,587 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 3 ms
5,248 KB
testcase_02 AC 3 ms
5,248 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 4 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 4 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 4 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 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, 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()
	C := make([]int, N+1)
	cost := 0
	for i := 0; i < N; i++ {
		C[i] = getInt()
		cost += C[i]
	}

	V -= N
	V = max(0, V)

	sum := make([]int, 110)
	best := 1
	for i := 0; i < N; i++ {
		sum[i+1] = sum[i] + C[i]
		if sum[i+1]*best < sum[best]*(i+1) {
			best = i + 1
		}
	}

	var dp [30010]int
	for i := 1; i < 25000; i++ {
		dp[i] = dp[i-1] + sum[1]
	}
	for i := 1; i <= N; i++ {
		for v := 0; v < 20000; v++ {
			dp[v+i] = min(dp[v+i], dp[v]+sum[i])
		}
	}
	times := max((V-15000)/best, 0)
	cost += times*sum[best] + dp[V-times*best]
	out(cost)
}
0