結果
問題 | No.2922 Rose Garden |
ユーザー |
|
提出日時 | 2024-10-12 15:31:29 |
言語 | Rust (1.83.0 + proconio) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,530 bytes |
コンパイル時間 | 12,868 ms |
コンパイル使用メモリ | 378,500 KB |
実行使用メモリ | 14,336 KB |
最終ジャッジ日時 | 2024-10-12 15:31:53 |
合計ジャッジ時間 | 21,343 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 3 |
other | TLE * 1 -- * 49 |
ソースコード
use proconio::input;fn main() {input! {(n, s, b): (usize, usize, usize),hh: [usize; n],}// dp[i]: スタミナがiのときの最高高度let mut dp = vec![None; s + 1];dp[s] = Some(hh[0]);let mut next_dp = vec![None; s + 1];for &h in &hh[1..] {for (stamina, &max_height) in dp.iter().enumerate() {let Some(max_height) = max_height else {continue;};for consumption in 0..=stamina {let cand_height = max_height + b * consumption;if cand_height >= h {chmax_for_option(&mut next_dp[stamina - consumption], cand_height);chmax_for_option(&mut next_dp[s], h);}}}std::mem::swap(&mut dp, &mut next_dp);next_dp.fill(None);}let ans = dp.iter().any(|max_height| max_height.is_some());println!("{}", if ans { "Yes" } else { "No" });}/// If `value` is `None` or contains a value less than `cand_value`, update it to `Some(cand_value)`.////// Returns whether `value` has been updated or not as a bool value.////// # Arguments////// * `value` - Reference variable to be updated./// * `cand_value` - Candidate value for update.pub fn chmax_for_option<T>(value: &mut Option<T>, cand_value: T) -> boolwhereT: PartialOrd,{if value.as_ref().is_some_and(|cost| cost >= &cand_value) {return false;}*value = Some(cand_value);true}