結果

問題 No.2390 Udon Coupon (Hard)
ユーザー koba-e964koba-e964
提出日時 2023-07-23 10:56:12
言語 Rust
(1.77.0)
結果
AC  
実行時間 353 ms / 2,000 ms
コード長 1,619 bytes
コンパイル時間 823 ms
コンパイル使用メモリ 161,664 KB
実行使用メモリ 64,436 KB
最終ジャッジ日時 2024-04-15 21:08:31
合計ジャッジ時間 10,546 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
64,384 KB
testcase_01 AC 82 ms
64,312 KB
testcase_02 AC 173 ms
64,216 KB
testcase_03 AC 171 ms
64,360 KB
testcase_04 AC 171 ms
64,380 KB
testcase_05 AC 82 ms
64,384 KB
testcase_06 AC 341 ms
64,384 KB
testcase_07 AC 83 ms
64,256 KB
testcase_08 AC 84 ms
64,336 KB
testcase_09 AC 340 ms
64,328 KB
testcase_10 AC 81 ms
64,344 KB
testcase_11 AC 82 ms
64,352 KB
testcase_12 AC 85 ms
64,360 KB
testcase_13 AC 83 ms
64,384 KB
testcase_14 AC 84 ms
64,436 KB
testcase_15 AC 81 ms
64,360 KB
testcase_16 AC 86 ms
64,384 KB
testcase_17 AC 79 ms
64,384 KB
testcase_18 AC 82 ms
64,340 KB
testcase_19 AC 83 ms
64,256 KB
testcase_20 AC 82 ms
64,208 KB
testcase_21 AC 84 ms
64,384 KB
testcase_22 AC 173 ms
64,312 KB
testcase_23 AC 171 ms
64,336 KB
testcase_24 AC 168 ms
64,348 KB
testcase_25 AC 175 ms
64,384 KB
testcase_26 AC 173 ms
64,384 KB
testcase_27 AC 176 ms
64,384 KB
testcase_28 AC 173 ms
64,364 KB
testcase_29 AC 174 ms
64,308 KB
testcase_30 AC 175 ms
64,384 KB
testcase_31 AC 171 ms
64,356 KB
testcase_32 AC 173 ms
64,340 KB
testcase_33 AC 168 ms
64,380 KB
testcase_34 AC 339 ms
64,296 KB
testcase_35 AC 349 ms
64,384 KB
testcase_36 AC 353 ms
64,356 KB
testcase_37 AC 334 ms
64,312 KB
testcase_38 AC 335 ms
64,344 KB
testcase_39 AC 122 ms
64,384 KB
testcase_40 AC 170 ms
64,356 KB
testcase_41 AC 166 ms
64,412 KB
testcase_42 AC 168 ms
64,384 KB
testcase_43 AC 170 ms
64,216 KB
testcase_44 AC 169 ms
64,348 KB
testcase_45 AC 169 ms
64,336 KB
testcase_46 AC 169 ms
64,384 KB
testcase_47 AC 167 ms
64,420 KB
testcase_48 AC 169 ms
64,384 KB
testcase_49 AC 80 ms
64,316 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes.by_ref().map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr,) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => { ($(read_value!($next, $t)),*) };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

fn main() {
    input! {
        n: i64,
        ab: [(usize, i64); 3],
    }
    const W: usize = 8_000_000;
    let mut dp = vec![0i64; W];
    for i in 1..W {
        let mut me = dp[i - 1];
        for &(a, b) in &ab {
            if i >= a {
                me = std::cmp::max(me, dp[i - a] + b);
            }
        }
        dp[i] = me;
    }
    let mut ans = 0;
    for &(a, b) in &ab {
        for i in 0..W {
            if i as i64 > n { continue; }
            let q = (n - i as i64) / a as i64;
            ans = std::cmp::max(ans, dp[i] + q * b);
        }
    }
    println!("{}", ans);
}
0