Skip to content

Commit

Permalink
pastbook2 joi2016ho_a
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Jun 8, 2023
1 parent bbb7b35 commit 1c1f731
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cargo-compete/pastbook2/Cargo.toml
Expand Up @@ -12,6 +12,7 @@ edition = "2018"
065 = { alias = "joi2014yo_d", problem = "https://atcoder.jp/contests/joi2014yo/tasks/joi2014yo_d" }
070 = { alias = "past202004_k", problem = "https://atcoder.jp/contests/past202004-open/tasks/past202004_k" }
078 = { alias = "pastbook2022_a", problem = "https://atcoder.jp/contests/pastbook2022/tasks/pastbook2022_a" }
082 = { alias = "joi2016ho_a", problem = "https://atcoder.jp/contests/joi2016ho/tasks/joi2016ho_a" }

[[bin]]
name = "027"
Expand Down Expand Up @@ -45,6 +46,10 @@ path = "src/bin/070.rs"
name = "078"
path = "src/bin/078.rs"

[[bin]]
name = "082"
path = "src/bin/082.rs"

[dependencies]
num = "=0.2.1"
num-bigint = "=0.2.6"
Expand Down
1 change: 1 addition & 0 deletions cargo-compete/pastbook2/README.md
Expand Up @@ -8,3 +8,4 @@
- P.65 joi2014yo_d 部活のスケジュール表 (日本情報オリンピック 予選 2014:D問題) <https://atcoder.jp/contests/joi2014yo/tasks/joi2014yo_d>
- P.70 括弧 (第二回 アルゴリズム実技検定:K問題) <https://atcoder.jp/contests/past202004-open/tasks/past202004_k>
- P.78 区間分割の仕方を最適化する問題 (オリジナル問題) <https://atcoder.jp/contests/pastbook2022/tasks/pastbook2022_a>
- P.82 オレンジの出荷 (日本情報オリンピック 本選 2016:A問題) <https://atcoder.jp/contests/joi2016ho/tasks/joi2016ho_a>
32 changes: 32 additions & 0 deletions cargo-compete/pastbook2/src/bin/082.rs
@@ -0,0 +1,32 @@
use proconio::input;

fn main() {
input! {
n: usize,
m: usize,
k: usize,
a: [usize; n],
}

let mut cost = vec![vec![0; m + 1]; n];
for i in 0..n {
let (mut min, mut max) = (1 << 60, 0);
for j in i..(i + m).min(n) {
let len = j - i + 1;
min = min.min(a[j]);
max = max.max(a[j]);
cost[i][len] = k + (max - min) * len;
}
}

let inf = 1_usize << 60;
let mut dp = vec![inf; n + 1];
dp[0] = 0_usize;
for i in 1..=n {
for j in i.saturating_sub(m)..i {
dp[i] = dp[i].min(dp[j] + cost[j][i - j]);
}
}
let ans = dp[n];
println!("{}", ans);
}

0 comments on commit 1c1f731

Please sign in to comment.