結果
問題 | No.2386 Udon Coupon (Easy) |
ユーザー |
👑 |
提出日時 | 2023-06-28 02:50:49 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 1,331 bytes |
コンパイル時間 | 11,943 ms |
コンパイル使用メモリ | 392,068 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-17 21:39:16 |
合計ジャッジ時間 | 13,306 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 37 |
ソースコード
fn main() { let mut input = String::with_capacity(1024); std::io::Read::read_to_string(&mut std::io::stdin(), &mut input).unwrap(); let mut tokens = input.split_whitespace(); let n = tokens.next().unwrap().parse::<usize>().unwrap(); let [a, b, c] = [ tokens.next().unwrap().parse::<u64>().unwrap(), tokens.next().unwrap().parse::<u64>().unwrap(), tokens.next().unwrap().parse::<u64>().unwrap(), ]; let mut dp = vec![0u64; n + 1]; let mut result = 0; for i in 0..=n { match i { 0..=2 => {} 3..=4 => { result.chmax(dp[i - 3] + a); } 5..=9 => { result.chmax(dp[i - 3] + a); result.chmax(dp[i - 5] + b); } _ => { result.chmax(dp[i - 3] + a); result.chmax(dp[i - 5] + b); result.chmax(dp[i - 10] + c); } } dp[i] = result; } println!("{}", result); } trait Change { fn chmax(&mut self, x: Self); fn chmin(&mut self, x: Self); } impl<T: PartialOrd> Change for T { fn chmax(&mut self, x: T) { if *self < x { *self = x; } } fn chmin(&mut self, x: T) { if *self > x { *self = x; } } }