結果

問題 No.1238 選抜クラス
ユーザー ccppjsrbccppjsrb
提出日時 2020-09-25 22:22:06
言語 Go
(1.22.1)
結果
TLE  
実行時間 -
コード長 2,750 bytes
コンパイル時間 15,548 ms
コンパイル使用メモリ 209,256 KB
実行使用メモリ 10,204 KB
最終ジャッジ日時 2023-09-10 15:37:46
合計ジャッジ時間 20,057 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 4 ms
5,480 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 1,759 ms
10,204 KB
testcase_18 TLE -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
権限があれば一括ダウンロードができます

ソースコード

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)
	k := getNextInt(scanner)
	aa := make([]int, n)
	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
	}
	var ans mint
	for i := 1; i < n+1; i++ {
		size := k*i + 1
		dp := makeGrid(i+1, size)
		dp[0][0] = 1
		for j := 0; j < n; j++ {
			for jj := i; jj > 0; jj-- {
				for jjj := size - 1; jjj >= 0; jjj-- {
					dp[jj][min(jjj+aa[j], size-1)].AddAs(dp[jj-1][jjj])
				}
			}
		}
		ans.AddAs(dp[i][size-1])
	}
	fmt.Fprintln(writer, ans)
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func makeGrid(h, w int) [][]mint {
	index := make([][]mint, h, h)
	data := make([]mint, h*w, h*w)
	for i := 0; i < h; i++ {
		index[i] = data[i*w : (i+1)*w]
	}
	return index
}

type mint int64

func (mt mint) Mod() mint {
	m := mint(1e9 + 7)
	mt %= m
	if mt < 0 {
		return mt + m
	}
	return mt
}
func (mt mint) Inv() mint {
	return mt.Pow(mint(0).Sub(2))
}
func (mt mint) Pow(n mint) mint {
	p := mint(1)
	for n > 0 {
		if n&1 == 1 {
			p.MulAs(mt)
		}
		mt.MulAs(mt)
		n >>= 1
	}
	return p
}
func (mt mint) Add(x mint) mint {
	return (mt + x).Mod()
}
func (mt mint) Sub(x mint) mint {
	return (mt - x).Mod()
}
func (mt mint) Mul(x mint) mint {
	return (mt * x).Mod()
}
func (mt mint) Div(x mint) mint {
	return mt.Mul(x.Inv())
}
func (mt *mint) AddAs(x mint) *mint {
	*mt = mt.Add(x)
	return mt
}
func (mt *mint) SubAs(x mint) *mint {
	*mt = mt.Sub(x)
	return mt
}
func (mt *mint) MulAs(x mint) *mint {
	*mt = mt.Mul(x)
	return mt
}
func (mt *mint) DivAs(x mint) *mint {
	*mt = mt.Div(x)
	return mt
}
0