結果
| 問題 | No.783 門松計画 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2021-11-08 22:11:22 | 
| 言語 | Rust (1.83.0 + proconio) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 25 ms / 2,000 ms | 
| コード長 | 2,388 bytes | 
| コンパイル時間 | 12,919 ms | 
| コンパイル使用メモリ | 378,880 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-11-15 05:21:51 | 
| 合計ジャッジ時間 | 14,226 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 27 | 
ソースコード
#[allow(unused_imports)]
use std::cmp::*;
// 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 ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}
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; } }
}
fn main() {
    input! {
        n: usize, c: usize,
        l: [usize; n],
        w: [usize; n],
    }
    const INF: i64 = 1 << 50;
    const B: usize = 51;
    let mut dp = vec![vec![vec![-INF; B]; B]; c + 1];
    let mut pr = vec![B; B];
    for i in 0..n {
        pr[l[i]].chmin(w[i]);
    }
    let mut ma = 0;
    for i in 0..B {
        if pr[i] == B { continue; }
        if pr[i] > c { continue; }
        for j in 0..B {
            if i == j || pr[j] == B { continue; }
            if pr[i] + pr[j] <= c {
                dp[pr[i] + pr[j]][i][j].chmax((i + j) as i64);
            }
        }
    }
    for i in 0..c + 1 {
        for j in 0..B {
            for k in 0..B {
                let val = dp[i][j][k];
                if val < 0 { continue; }
                for l in 0..B {
                    if pr[l] + i > c { continue; }
                    // katomatsu
                    if j != l && k != l && j.cmp(&k) == l.cmp(&k) {
                        dp[i + pr[l]][k][l].chmax(val + l as i64);
                        ma.chmax(val + l as i64);
                    }
                }
            }
        }
    }
    println!("{}", ma);
}
            
            
            
        