結果

問題 No.10 +か×か
ユーザー neko_the_shadowneko_the_shadow
提出日時 2019-12-16 13:22:30
言語 Go
(1.22.1)
結果
WA  
実行時間 -
コード長 969 bytes
コンパイル時間 12,780 ms
コンパイル使用メモリ 211,816 KB
実行使用メモリ 113,244 KB
最終ジャッジ日時 2023-09-15 17:34:13
合計ジャッジ時間 12,530 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,356 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 1 ms
4,380 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 30 ms
12,196 KB
testcase_09 AC 17 ms
7,828 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

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

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

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

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

	k := t
	ans := make([]string, n-1)
	for i := n - 1; i >= 1; i-- {
		v := dp[i][k]
		if k == v+a[i] {
			ans[i-1] = "+"
		} else {
			ans[i-1] = "*"
		}
		k = v
	}

	fmt.Println(strings.Join(ans, ""))
}

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