結果

問題 No.10 +か×か
ユーザー neko_the_shadowneko_the_shadow
提出日時 2019-12-16 13:51:41
言語 Go
(1.22.1)
結果
AC  
実行時間 1,689 ms / 5,000 ms
コード長 943 bytes
コンパイル時間 15,635 ms
コンパイル使用メモリ 234,168 KB
実行使用メモリ 283,608 KB
最終ジャッジ日時 2024-05-08 11:59:40
合計ジャッジ時間 17,859 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1,689 ms
276,736 KB
testcase_04 AC 11 ms
5,504 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1,640 ms
283,608 KB
testcase_07 AC 609 ms
100,864 KB
testcase_08 AC 81 ms
18,432 KB
testcase_09 AC 44 ms
10,880 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,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