結果

問題 No.45 回転寿司
ユーザー seiichiseiichi
提出日時 2021-01-14 16:25:36
言語 Go
(1.21.3)
結果
RE  
実行時間 -
コード長 1,274 bytes
コンパイル時間 10,849 ms
コンパイル使用メモリ 209,200 KB
実行使用メモリ 103,668 KB
最終ジャッジ日時 2023-08-15 22:21:26
合計ジャッジ時間 15,588 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
46,320 KB
testcase_01 AC 135 ms
62,704 KB
testcase_02 AC 195 ms
85,232 KB
testcase_03 AC 211 ms
93,428 KB
testcase_04 AC 143 ms
66,800 KB
testcase_05 AC 26 ms
15,588 KB
testcase_06 AC 118 ms
56,564 KB
testcase_07 AC 184 ms
85,236 KB
testcase_08 AC 63 ms
31,976 KB
testcase_09 AC 197 ms
89,328 KB
testcase_10 AC 98 ms
48,360 KB
testcase_11 AC 56 ms
29,932 KB
testcase_12 AC 193 ms
87,280 KB
testcase_13 AC 24 ms
15,584 KB
testcase_14 AC 17 ms
11,492 KB
testcase_15 AC 106 ms
52,456 KB
testcase_16 AC 69 ms
36,072 KB
testcase_17 AC 91 ms
46,312 KB
testcase_18 AC 71 ms
38,124 KB
testcase_19 AC 169 ms
77,040 KB
testcase_20 AC 16 ms
13,304 KB
testcase_21 AC 23 ms
13,540 KB
testcase_22 AC 3 ms
7,160 KB
testcase_23 AC 3 ms
7,156 KB
testcase_24 AC 4 ms
7,156 KB
testcase_25 RE -
testcase_26 AC 104 ms
50,408 KB
testcase_27 AC 171 ms
77,040 KB
testcase_28 AC 113 ms
54,504 KB
testcase_29 AC 153 ms
70,896 KB
testcase_30 AC 162 ms
72,944 KB
testcase_31 AC 3 ms
7,156 KB
testcase_32 AC 3 ms
7,156 KB
testcase_33 AC 240 ms
103,668 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}

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

	// N=1or2の時はシンプルなので先に埋めちゃう
	dp[0][V[0]] = true
	dp[1][V[1]] = true
	max_val[0] = V[0]
	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