結果
問題 |
No.2150 Site Supporter
|
ユーザー |
|
提出日時 | 2022-12-18 12:26:41 |
言語 | Go (1.23.4) |
結果 |
AC
|
実行時間 | 17 ms / 2,000 ms |
コード長 | 1,050 bytes |
コンパイル時間 | 17,597 ms |
コンパイル使用メモリ | 243,492 KB |
実行使用メモリ | 7,040 KB |
最終ジャッジ日時 | 2024-11-17 23:21:32 |
合計ジャッジ時間 | 14,143 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 |
ソースコード
package main import ( "bufio" "fmt" "os" "strconv" ) var sc = bufio.NewScanner(os.Stdin) var out = bufio.NewWriter(os.Stdout) func main() { buf := make([]byte, 1024*1024) sc.Buffer(buf, bufio.MaxScanTokenSize) sc.Split(bufio.ScanWords) n, k, x := nextInt(), nextInt(), nextInt() a := nextIntSlice(n) ans := solve(n, k, x, a) PrintInt(ans) } func solve(n, k, x int, a []int) int { //i日目にサポータか否か(0:非サポーター、1:サポーター)で払う金額の最小値 dp := make([][2]int, n+1) dp[0][1] = 1 << 60 for i := 1; i <= n; i++ { dp[i][0] = Min(dp[i-1][0]+a[i-1], dp[i-1][1]+a[i-1]) dp[i][1] = Min(dp[i-1][0]+x+k, dp[i-1][1]+k) } //fmt.Println(dp) return Min(dp[n][0], dp[n][1]) } func nextInt() int { sc.Scan() i, _ := strconv.Atoi(sc.Text()) return i } func nextIntSlice(n int) []int { s := make([]int, n) for i := range s { s[i] = nextInt() } return s } func PrintInt(x int) { defer out.Flush() fmt.Fprintln(out, x) } func Min(x, y int) int { if x < y { return x } return y }