結果

問題 No.664 超能力者Aと株価予測
ユーザー ccppjsrbccppjsrb
提出日時 2020-06-06 21:37:00
言語 Go
(1.21.3)
結果
AC  
実行時間 40 ms / 4,000 ms
コード長 2,803 bytes
コンパイル時間 11,115 ms
コンパイル使用メモリ 211,792 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-25 02:00:39
合計ジャッジ時間 12,127 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

package main

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

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	m := getNextInt(scanner)
	k := getNextInt(scanner)
	aa := make([]int, n+1)
	for i := 0; i < n+1; i++ {
		aa[i] = getNextInt(scanner)
	}
	dp := makeGrid(n+1, m+1)
	dp[0][0] = cint(k)
	for to := 1; to < n+1; to++ {
		for from := 0; from < to; from++ {
			for i := 0; i < m+1; i++ {
				dp[to][i].maxAs(dp[from][i])
			}
			for i := 1; i < m+1; i++ {
				dp[to][i].maxAs(dp[from][i-1].div(aa[from]).mul(aa[to]).add(dp[from][i-1] % cint(aa[from])))
			}
		}
	}
	var ans cint
	for i := 0; i < m+1; i++ {
		ans.maxAs(dp[n][i])
	}
	fmt.Fprintln(writer, ans)
}

func makeGrid(h, w int) [][]cint {
	index := make([][]cint, h, h)
	data := make([]cint, h*w, h*w)
	for i := 0; i < h; i++ {
		index[i] = data[i*w : (i+1)*w]
	}
	return index
}

type cint int64

func (ct *cint) cintize(x interface{}) cint {
	if y, isCint := x.(cint); isCint {
		return y
	}
	if y, isInt64 := x.(int64); isInt64 {
		return cint(y)
	}
	return cint(x.(int))
}
func (ct *cint) minAs(x interface{}) *cint {
	*ct = ct.min(x)
	return ct
}
func (ct *cint) maxAs(x interface{}) *cint {
	*ct = ct.max(x)
	return ct
}
func (ct cint) min(x interface{}) cint {
	y := ct.cintize(x)
	if ct > y {
		return y
	}
	return ct
}
func (ct cint) max(x interface{}) cint {
	y := ct.cintize(x)
	if ct < y {
		return y
	}
	return ct
}
func (ct cint) add(x interface{}) cint {
	return ct + ct.cintize(x)
}
func (ct cint) sub(x interface{}) cint {
	return ct - ct.cintize(x)
}
func (ct cint) mul(x interface{}) cint {
	return ct * ct.cintize(x)
}
func (ct cint) div(x interface{}) cint {
	return ct / ct.cintize(x)
}
0