結果

問題 No.10 +か×か
ユーザー neko_the_shadowneko_the_shadow
提出日時 2019-12-16 13:51:41
言語 Go
(1.22.1)
結果
AC  
実行時間 1,638 ms / 5,000 ms
コード長 943 bytes
コンパイル時間 12,471 ms
コンパイル使用メモリ 211,052 KB
実行使用メモリ 275,012 KB
最終ジャッジ日時 2023-08-21 06:27:12
合計ジャッジ時間 17,316 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1,638 ms
274,936 KB
testcase_04 AC 12 ms
5,968 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1,623 ms
275,012 KB
testcase_07 AC 551 ms
108,056 KB
testcase_08 AC 76 ms
19,472 KB
testcase_09 AC 44 ms
11,496 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

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

func main() {
	n := readInt()
	t := readInt()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = readInt()
	}

	dp := make([]map[int]string, n)
	for i := 0; i < n; i++ {
		dp[i] = make(map[int]string)
	}
	dp[0][a[0]] = ""

	for i := 1; i < n; i++ {
		for k := range dp[i-1] {
			if k*a[i] <= t {
				dp[i][k*a[i]] = max(dp[i][k*a[i]], dp[i-1][k]+"*")
			}
			if k+a[i] <= t {
				dp[i][k+a[i]] = max(dp[i][k+a[i]], dp[i-1][k]+"+")
			}
		}
	}

	fmt.Println(dp[n-1][t])
}

func max(x string, y string) string {
	if x < y {
		return y
	} else {
		return x
	}
}

var stdin *bufio.Scanner

func read() string {
	if stdin == nil {
		stdin = bufio.NewScanner(os.Stdin)
		stdin.Split(bufio.ScanWords)
		stdin.Buffer(make([]byte, bufio.MaxScanTokenSize), int(math.MaxInt32))
	}
	stdin.Scan()
	return stdin.Text()
}

func readInt() int {
	n, _ := strconv.Atoi(read())
	return n
}
0