結果

問題 No.1199 お菓子配り-2
ユーザー 小野寺健小野寺健
提出日時 2021-12-20 09:47:55
言語 Go
(1.22.1)
結果
AC  
実行時間 684 ms / 1,000 ms
コード長 994 bytes
コンパイル時間 13,332 ms
コンパイル使用メモリ 206,024 KB
実行使用メモリ 12,536 KB
最終ジャッジ日時 2023-10-13 19:27:53
合計ジャッジ時間 42,484 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,372 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,992 KB
testcase_03 AC 170 ms
6,668 KB
testcase_04 AC 425 ms
9,872 KB
testcase_05 AC 14 ms
4,988 KB
testcase_06 AC 24 ms
4,972 KB
testcase_07 AC 207 ms
6,632 KB
testcase_08 AC 284 ms
6,408 KB
testcase_09 AC 171 ms
6,140 KB
testcase_10 AC 43 ms
4,992 KB
testcase_11 AC 134 ms
6,176 KB
testcase_12 AC 131 ms
6,164 KB
testcase_13 AC 44 ms
4,972 KB
testcase_14 AC 38 ms
4,984 KB
testcase_15 AC 32 ms
4,976 KB
testcase_16 AC 277 ms
7,072 KB
testcase_17 AC 134 ms
6,168 KB
testcase_18 AC 294 ms
9,828 KB
testcase_19 AC 76 ms
6,152 KB
testcase_20 AC 517 ms
9,516 KB
testcase_21 AC 322 ms
10,472 KB
testcase_22 AC 172 ms
9,380 KB
testcase_23 AC 238 ms
9,744 KB
testcase_24 AC 323 ms
9,828 KB
testcase_25 AC 48 ms
4,972 KB
testcase_26 AC 360 ms
7,552 KB
testcase_27 AC 289 ms
6,404 KB
testcase_28 AC 680 ms
10,600 KB
testcase_29 AC 682 ms
10,600 KB
testcase_30 AC 683 ms
10,596 KB
testcase_31 AC 681 ms
10,596 KB
testcase_32 AC 683 ms
10,600 KB
testcase_33 AC 684 ms
10,592 KB
testcase_34 AC 681 ms
10,596 KB
testcase_35 AC 681 ms
10,596 KB
testcase_36 AC 680 ms
10,600 KB
testcase_37 AC 680 ms
10,600 KB
testcase_38 AC 681 ms
10,596 KB
testcase_39 AC 682 ms
10,596 KB
testcase_40 AC 682 ms
10,596 KB
testcase_41 AC 681 ms
10,660 KB
testcase_42 AC 681 ms
10,596 KB
testcase_43 AC 675 ms
10,604 KB
testcase_44 AC 674 ms
12,300 KB
testcase_45 AC 678 ms
12,536 KB
testcase_46 AC 678 ms
12,536 KB
testcase_47 AC 677 ms
12,532 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

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

func Max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func Add(a, b int) int {
	if a == math.MinInt64 {
		return a
	} else {
		return a + b
	}
}

func main() {
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()
	var n, m int
	fmt.Fscan(r, &n, &m)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		sum := 0
		for j := 0; j < m; j++ {
			var x int
			fmt.Fscan(r, &x)
			sum += x
		}
		a[i] = sum
	}
	dp := make([][]int, n+1)
	for i := 0; i <= n; i++ {
		dp[i] = make([]int, n+1)
		for j := 0; j <= n; j++ {
			dp[i][j] = math.MinInt64
		}
	}
	dp[0][0] = 0
	for i := 1; i <= n; i++ {
		dp[i][0] = 0
		for j := 1; j <= n; j++ {
			if j % 2 == 1 {
				dp[i][j] = Max(dp[i-1][j], Add(dp[i-1][j-1], a[i-1]))
			} else {
				dp[i][j] = Max(dp[i-1][j], Add(dp[i-1][j-1], -a[i-1]))
			}
		}
	}
	max := math.MinInt64
	for i := 0; i <= n; i++ {
		max = Max(max, dp[n][i])
	}
	fmt.Fprintln(w, max)
}
0