結果

問題 No.783 門松計画
ユーザー koba-e964koba-e964
提出日時 2021-11-08 22:12:37
言語 Rust
(1.77.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 2,346 bytes
コンパイル時間 13,020 ms
コンパイル使用メモリ 383,604 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-27 05:09:39
合計ジャッジ時間 14,209 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 1 ms
6,944 KB
testcase_10 AC 4 ms
6,944 KB
testcase_11 AC 25 ms
6,944 KB
testcase_12 AC 8 ms
6,940 KB
testcase_13 AC 3 ms
6,940 KB
testcase_14 AC 3 ms
6,940 KB
testcase_15 AC 1 ms
6,940 KB
testcase_16 AC 1 ms
6,944 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 1 ms
6,940 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 1 ms
6,940 KB
testcase_21 AC 1 ms
6,940 KB
testcase_22 AC 1 ms
6,940 KB
testcase_23 AC 1 ms
6,940 KB
testcase_24 AC 1 ms
6,944 KB
testcase_25 AC 1 ms
6,940 KB
testcase_26 AC 2 ms
6,940 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 ; $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);
}
0