結果

問題 No.2095 High Rise
ユーザー urutomurutom
提出日時 2022-10-16 10:06:06
言語 Go
(1.22.1)
結果
AC  
実行時間 117 ms / 2,000 ms
コード長 1,130 bytes
コンパイル時間 13,790 ms
コンパイル使用メモリ 209,952 KB
実行使用メモリ 8,136 KB
最終ジャッジ日時 2023-09-09 14:09:07
合計ジャッジ時間 15,912 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 2 ms
4,356 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 2 ms
4,356 KB
testcase_05 AC 1 ms
4,388 KB
testcase_06 AC 1 ms
4,356 KB
testcase_07 AC 2 ms
4,356 KB
testcase_08 AC 2 ms
4,356 KB
testcase_09 AC 2 ms
4,356 KB
testcase_10 AC 2 ms
4,356 KB
testcase_11 AC 2 ms
4,352 KB
testcase_12 AC 2 ms
4,352 KB
testcase_13 AC 1 ms
4,352 KB
testcase_14 AC 2 ms
4,352 KB
testcase_15 AC 2 ms
4,352 KB
testcase_16 AC 1 ms
4,356 KB
testcase_17 AC 15 ms
5,548 KB
testcase_18 AC 10 ms
4,356 KB
testcase_19 AC 4 ms
4,352 KB
testcase_20 AC 16 ms
5,552 KB
testcase_21 AC 30 ms
7,852 KB
testcase_22 AC 117 ms
8,132 KB
testcase_23 AC 117 ms
8,136 KB
testcase_24 AC 117 ms
8,132 KB
testcase_25 AC 115 ms
8,136 KB
testcase_26 AC 116 ms
8,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

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

const MaxInt = math.MaxInt64

var scanner *bufio.Scanner

func init() {
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Buffer([]byte{}, MaxInt)
	scanner.Split(bufio.ScanWords)
}

func Int() int {
	var w string
	if scanner.Scan() {
		w = scanner.Text()
	}
	ret, _ := strconv.ParseInt(w, 10, 0)
	return int(ret)
}

func Min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	n := Int()
	m := Int()
	a := make([]int, m)
	dp := make([]int, m)
	for j := 0; j < m; j++ {
		a[j] = Int()
	}
	if n == 1 {
		fmt.Println(0)
		return
	}
	b := make([]int, m)
	for j := 0; j < m; j++ {
		b[j] = Int()
		dp[j] = a[j] + b[j]
	}
	a = b
	for i := 2; i < n; i++ {
		k := 0
		minVal := dp[0]
		for j := 1; j < m; j++ {
			if dp[j] < minVal {
				k = j
				minVal = dp[j]
			}
		}
		nextA := make([]int, m)
		nextDP := make([]int, m)
		for j := 0; j < m; j++ {
			nextA[j] = Int()
			nextDP[j] = nextA[j] + Min(dp[j], dp[k]+a[j])
		}
		a = nextA
		dp = nextDP
	}

	ans := dp[0]
	for j := 1; j < m; j++ {
		if dp[j] < ans {
			ans = dp[j]
		}
	}
	fmt.Println(ans)
}
0