結果
| 問題 |
No.45 回転寿司
|
| ユーザー |
K.T
|
| 提出日時 | 2020-07-03 11:21:37 |
| 言語 | Go (1.23.4) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 1,232 bytes |
| コンパイル時間 | 15,541 ms |
| コンパイル使用メモリ | 229,488 KB |
| 実行使用メモリ | 820,368 KB |
| 最終ジャッジ日時 | 2024-09-16 16:19:22 |
| 合計ジャッジ時間 | 26,312 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 4 |
| other | MLE * 1 -- * 29 |
ソースコード
package main
import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
)
func main() {
stdin := bufio.NewScanner(os.Stdin)
//fmt.Print(">")
stdin.Scan()
i, _ := strconv.Atoi(stdin.Text())
//fmt.Print(">")
stdin.Scan()
slice := strings.Split(stdin.Text(), " ")
if len(slice) != i {
fmt.Println("少ない")
return
}
Deliciousness := make([]int, 0)
for _, s := range slice {
j, _ := strconv.Atoi(s)
Deliciousness = append(Deliciousness, j)
}
max := 0
//maxindex := ""
for _, value := range aaa(Deliciousness, "", map[string]int{}) {
if max < value {
max = value
//maxindex = index
}
}
fmt.Println(max)
}
func aaa(List []int, Key string, selected map[string]int) map[string]int {
for i, a := range List {
if a < 0 {
continue
}
b := make([]int, len(List))
copy(b, List)
newKey := ""
if Key == "" {
newKey = strconv.Itoa(i + 1)
selected[newKey] = b[i]
} else {
newKey = Key + "-" + strconv.Itoa(i+1)
selected[newKey] = selected[Key] + b[i]
}
b[i] = -1
if i-1 >= 0 {
b[i-1] = -1
}
if i+1 < len(b) {
b[i+1] = -1
}
sum := 0
for _, x := range b {
sum += x
}
if sum < 0 {
return selected
}
aaa(b, newKey, selected)
}
return selected
}
K.T