結果

問題 No.45 回転寿司
ユーザー seiichiseiichi
提出日時 2021-01-14 16:27:26
言語 Go
(1.22.1)
結果
AC  
実行時間 244 ms / 5,000 ms
コード長 1,318 bytes
コンパイル時間 10,690 ms
コンパイル使用メモリ 213,356 KB
実行使用メモリ 103,664 KB
最終ジャッジ日時 2023-08-15 22:23:23
合計ジャッジ時間 15,811 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 98 ms
46,312 KB
testcase_01 AC 139 ms
62,704 KB
testcase_02 AC 194 ms
85,232 KB
testcase_03 AC 214 ms
93,428 KB
testcase_04 AC 148 ms
66,804 KB
testcase_05 AC 28 ms
15,584 KB
testcase_06 AC 122 ms
56,560 KB
testcase_07 AC 193 ms
85,232 KB
testcase_08 AC 65 ms
31,976 KB
testcase_09 AC 205 ms
89,332 KB
testcase_10 AC 102 ms
48,364 KB
testcase_11 AC 58 ms
29,932 KB
testcase_12 AC 203 ms
87,284 KB
testcase_13 AC 26 ms
15,588 KB
testcase_14 AC 18 ms
11,268 KB
testcase_15 AC 111 ms
52,456 KB
testcase_16 AC 72 ms
36,072 KB
testcase_17 AC 96 ms
46,312 KB
testcase_18 AC 76 ms
38,124 KB
testcase_19 AC 172 ms
77,044 KB
testcase_20 AC 17 ms
13,300 KB
testcase_21 AC 24 ms
13,536 KB
testcase_22 AC 4 ms
7,156 KB
testcase_23 AC 4 ms
7,160 KB
testcase_24 AC 5 ms
7,156 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 109 ms
50,408 KB
testcase_27 AC 173 ms
77,044 KB
testcase_28 AC 118 ms
54,504 KB
testcase_29 AC 159 ms
70,896 KB
testcase_30 AC 163 ms
72,944 KB
testcase_31 AC 3 ms
7,156 KB
testcase_32 AC 4 ms
7,156 KB
testcase_33 AC 244 ms
103,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"fmt"
)

func scan() (N int, V []int) {
	fmt.Scan(&N)
	for i := 0; i < N; i++ {
		var v int
		fmt.Scan(&v)
		V = append(V, v)
	}
	return
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func main() {
	N, V := scan()
	// N := 3
	// V := []int{1, 2, 3}
	// N := 4
	// V := []int{1, 2, 3, 4}
	// N := 4
	// V := []int{5, 4, 4, 9}
	// N := 7
	// V := []int{1, 2, 9, 10, 1, 1, 4}
	// N := 1
	// V := []int{100}
	// N := 2
	// V := []int{45, 32}

	if N == 1 {
		fmt.Print(V[0])
		return
	}

	// 皿Nが与えられた場合のおいしさの最大値のマッピングリスト
	// NはN-1の結果から得られるので、全探索は必要ない
	var dp [1000][1000 * 100]bool
	var max_val [1000]int

	// N=1or2の時はシンプルなので先に埋めちゃう
	dp[0][V[0]] = true
	max_val[0] = V[0]
	dp[1][V[1]] = true
	max_val[1] = V[1]

	for i := 0; i < N; i++ {
		if i-2 >= 0 {
			for j := 0; j < len(dp[i-2]); j++ {
				if dp[i-2][j] {
					dp[i][V[i]+j] = true
					if V[i]+j > max_val[i] {
						max_val[i] = V[i] + j
					}
				}
			}
		}
		if i-3 >= 0 {
			for j := 0; j < len(dp[i-3]); j++ {
				if dp[i-3][j] {
					dp[i][V[i]+j] = true
					if V[i]+j > max_val[i] {
						max_val[i] = V[i] + j
					}
				}
			}
		}
	}
	fmt.Print(max(max_val[N-1], max_val[N-2]))
}
0