結果

問題 No.664 超能力者Aと株価予測
ユーザー ccppjsrbccppjsrb
提出日時 2020-06-06 21:27:47
言語 Go
(1.22.1)
結果
WA  
実行時間 -
コード長 2,735 bytes
コンパイル時間 11,520 ms
コンパイル使用メモリ 213,728 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-25 01:59:17
合計ジャッジ時間 12,643 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 2 ms
4,376 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 26 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 c := 0; c < m; c++ {
		for i := 0; i < n; i++ {
			for j := i + 1; j < n+1; j++ {
				dp[j][c].maxAs(dp[i][c])
				dp[j][c+1].maxAs(dp[i][c].div(aa[i]).mul(aa[j]).add(dp[i][c] % cint(aa[i])))
			}
		}
	}
	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 int

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