結果

問題 No.2386 Udon Coupon (Easy)
コンテスト
ユーザー 👑 Mizar
提出日時 2023-06-28 02:50:49
言語 Rust
(1.94.0 + proconio + num + itertools)
コンパイル:
/usr/bin/rustc_custom
実行:
./target/release/main
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,331 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 7,126 ms
コンパイル使用メモリ 192,608 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-04-06 11:32:25
合計ジャッジ時間 8,300 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 37
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: method `chmin` is never used
  --> src/main.rs:39:8
   |
37 | trait Change {
   |       ------ method in this trait
38 |     fn chmax(&mut self, x: Self);
39 |     fn chmin(&mut self, x: Self);
   |        ^^^^^
   |
   = note: `#[warn(dead_code)]` (part of `#[warn(unused)]`) on by default

ソースコード

diff #
raw source code

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;
        }
    }
}
0