結果

問題 No.115 遠足のおやつ
ユーザー ccppjsrbccppjsrb
提出日時 2020-06-01 22:56:33
言語 Go
(1.22.1)
結果
AC  
実行時間 10 ms / 5,000 ms
コード長 3,036 bytes
コンパイル時間 12,894 ms
コンパイル使用メモリ 203,332 KB
実行使用メモリ 5,536 KB
最終ジャッジ日時 2023-08-31 00:59:11
合計ジャッジ時間 14,556 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

package main

import (
	"bufio"
	"fmt"
	"math/big"
	"os"
	"strconv"
	"strings"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}
func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	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 getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(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
	cnt := 0
	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 3
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}
	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	d := getNextInt(scanner)
	k := getNextInt(scanner)
	dp := makeGrid(k+1, d+1)
	for i := 0; i < k+1; i++ {
		for j := 0; j < d+1; j++ {
			dp[i][j] = newBint(0)
		}
	}
	dp[0][0].x.Add(dp[0][0].x, big.NewInt(1))
	for i := n; i > 0; i-- {
		for ii := k; ii > 0; ii-- {
			for iii := d; iii >= i; iii-- {
				if dp[ii-1][iii-i].x.Bit(0) == 0 {
					continue
				}
				dp[ii][iii].x.SetBit(dp[ii-1][iii-i].x, i, 1)
			}
		}
	}
	if dp[k][d].x.Bit(0) == 0 {
		fmt.Fprintln(writer, -1)
		return
	}
	ans := make([]string, 0)
	for i := 1; i <= n; i++ {
		if dp[k][d].x.Bit(i) == 0 {
			continue
		}
		ans = append(ans, fmt.Sprintf("%d", i))
	}
	fmt.Fprintln(writer, strings.Join(ans, " "))
}
func makeGrid(h, w int) [][]*bint {
	index := make([][]*bint, h, h)
	data := make([]*bint, h*w, h*w)
	for i := 0; i < h; i++ {
		index[i] = data[i*w : (i+1)*w]
	}
	return index
}

type bint struct {
	x *big.Int
}

func newBint(x int64) *bint {
	return &bint{x: big.NewInt(x)}
}
func (x *bint) add(y *bint) *bint {
	z := newBint(0)
	z.x.Add(x.x, y.x)
	return z
}
func (x *bint) sub(y *bint) *bint {
	z := newBint(0)
	z.x.Sub(x.x, y.x)
	return z
}
func (x *bint) mul(y *bint) *bint {
	z := newBint(0)
	z.x.Mul(x.x, y.x)
	return z
}
func (x *bint) div(y *bint) *bint {
	z := newBint(0)
	z.x.Div(x.x, y.x)
	return z
}
func (x *bint) lsh(n int) *bint {
	z := newBint(0)
	z.x.Lsh(x.x, uint(n))
	return z
}
func (x *bint) rsh(n int) *bint {
	z := newBint(0)
	z.x.Rsh(x.x, uint(n))
	return z
}
func (x *bint) or(y *bint) *bint {
	z := newBint(0)
	z.x.Or(x.x, y.x)
	return z
}
func (x *bint) and(y *bint) *bint {
	z := newBint(0)
	z.x.And(x.x, y.x)
	return z
}
0