結果

問題 No.115 遠足のおやつ
ユーザー aru aruaru aru
提出日時 2020-08-11 12:58:08
言語 Go
(1.22.1)
結果
TLE  
実行時間 -
コード長 1,745 bytes
コンパイル時間 10,120 ms
コンパイル使用メモリ 226,116 KB
実行使用メモリ 13,888 KB
最終ジャッジ日時 2024-04-17 17:14:08
合計ジャッジ時間 16,883 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,152 KB
testcase_01 AC 1 ms
6,816 KB
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
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 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
権限があれば一括ダウンロードができます

ソースコード

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, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - 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 next(a []int, N int) []int {
	n := len(a) - 1
	a[n]++
	for i := n; i > 0; i-- {
		if a[i] > N {
			a[i] -= N + 1
			a[i-1]++
		} else {
			break
		}
	}
	return a
}

func main() {
	sc.Split(bufio.ScanWords)
	N, D, K := getInt(), getInt(), getInt()

	if D > N*(N+1)/2 {
		out(-1)
		return
	}

	tot := 0
	a := make([]int, 0)
	for i := 1; i <= K; i++ {
		a = append(a, i)
		tot += i
	}

	for {
		flg := true
		for i := 1; i < len(a); i++ {
			if a[i] <= a[i-1] {
				flg = false
				break
			}
		}
		if flg {
			// out(a)
			tot := 0
			for _, v := range a {
				tot += v
			}
			if tot == D {
				for i := 0; i < len(a); i++ {
					fmt.Print(a[i], " ")
				}
				out()
				return
			}
		}
		a = next(a, N)
		if a[0] == N+2-len(a) {
			break
		}
	}
	out(-1)
}
0