結果

問題 No.10 +か×か
ユーザー warashiwarashi
提出日時 2015-10-25 18:42:57
言語 Go
(1.22.1)
結果
TLE  
実行時間 -
コード長 686 bytes
コンパイル時間 10,879 ms
コンパイル使用メモリ 225,964 KB
実行使用メモリ 15,136 KB
最終ジャッジ日時 2024-04-19 03:28:04
合計ジャッジ時間 17,568 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,820 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"fmt"
)

var N, TOTAL int
var A []int

type in struct {
	i, total int
}
type out struct {
	can bool
	m   string
}

var cache = make(map[in]out)

func main() {
	fmt.Scan(&N, &TOTAL)
	A = make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&A[i])
	}

	can, str := calc(1, A[0], "")
	if can {
		fmt.Println(str)
	}
}

func calc(i, n int, m string) (bool, string) {
	if c, ok := cache[in{i, n}]; ok {
		return c.can, c.m
	}
	if i == N {
		if n == TOTAL {
			return true, m
		} else {
			return false, m
		}
	}

	p, ps := calc(i+1, n+A[i], m+"+")
	if p {
		return true, ps
	}
	mul, muls := calc(i+1, n*A[i], m+"*")
	if mul {
		return true, muls
	}
	return false, m
}
0