結果

問題 No.2317 Expression Menu
ユーザー 👑 tipstar0125tipstar0125
提出日時 2023-05-31 18:34:39
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 4,722 bytes
コンパイル時間 2,646 ms
コンパイル使用メモリ 158,300 KB
実行使用メモリ 217,072 KB
最終ジャッジ日時 2023-08-28 01:36:16
合計ジャッジ時間 15,192 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 24 ms
17,180 KB
testcase_03 AC 328 ms
216,988 KB
testcase_04 WA -
testcase_05 AC 324 ms
217,028 KB
testcase_06 AC 325 ms
217,060 KB
testcase_07 AC 324 ms
217,064 KB
testcase_08 AC 324 ms
216,984 KB
testcase_09 AC 329 ms
217,056 KB
testcase_10 AC 324 ms
216,988 KB
testcase_11 AC 327 ms
217,052 KB
testcase_12 AC 326 ms
217,028 KB
testcase_13 AC 325 ms
216,964 KB
testcase_14 AC 327 ms
217,032 KB
testcase_15 AC 323 ms
216,992 KB
testcase_16 AC 325 ms
216,980 KB
testcase_17 AC 325 ms
217,032 KB
testcase_18 AC 325 ms
217,056 KB
testcase_19 AC 328 ms
217,056 KB
testcase_20 AC 329 ms
217,060 KB
testcase_21 AC 324 ms
216,980 KB
testcase_22 AC 327 ms
216,984 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 384 ms
216,972 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 389 ms
216,976 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 WA -
testcase_39 AC 399 ms
216,976 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#![allow(non_snake_case)]
#![allow(unused_imports)]
#![allow(unused_macros)]
#![allow(clippy::needless_range_loop)]
#![allow(clippy::comparison_chain)]
#![allow(clippy::nonminimal_bool)]
#![allow(clippy::neg_multiply)]
#![allow(dead_code)]
use std::cmp::Reverse;
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, VecDeque};

#[derive(Default)]
struct Solver {}
impl Solver {
    fn solve(&mut self) {
        input! {
            N: usize,
            X: usize,
            Y: usize,
            ABC: [(usize, usize, isize); N]
        }

        let INF = 1_isize << 60;
        let mut dp = vec![vec![vec![-INF; Y + 1]; X + 1]; N + 1];
        dp[0][0][0] = 0;

        for i in 1..=N {
            let (a, b, c) = ABC[i - 1];
            for j in 0..=X {
                for k in 0..=Y {
                    dp[i][j][k] = max!(dp[i][j][k], dp[i - 1][j][k]);
                    if j + a <= X && k + b <= Y {
                        dp[i][j + a][k + b] = max!(dp[i][j + a][k + b], dp[i - 1][j][k] + c);
                    }
                }
            }
        }
        let mut ans = -1;
        for i in 0..=X {
            for j in 0..Y {
                ans = max!(ans, dp[N][i][j]);
            }
        }
        println!("{}", ans);
    }
}

#[macro_export]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $( $y: expr ),+) => {
        std::cmp::max($x, max!($( $y ),+))
    }
}
#[macro_export]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $( $y: expr ),+) => {
        std::cmp::min($x, min!($( $y ),+))
    }
}

fn main() {
    std::thread::Builder::new()
        .stack_size(128 * 1024 * 1024)
        .spawn(|| Solver::default().solve())
        .unwrap()
        .join()
        .unwrap();
}

#[macro_export]
macro_rules! input {
    () => {};
    (mut $var:ident: $t:tt, $($rest:tt)*) => {
        let mut $var = __input_inner!($t);
        input!($($rest)*)
    };
    ($var:ident: $t:tt, $($rest:tt)*) => {
        let $var = __input_inner!($t);
        input!($($rest)*)
    };
    (mut $var:ident: $t:tt) => {
        let mut $var = __input_inner!($t);
    };
    ($var:ident: $t:tt) => {
        let $var = __input_inner!($t);
    };
}

#[macro_export]
macro_rules! __input_inner {
    (($($t:tt),*)) => {
        ($(__input_inner!($t)),*)
    };
    ([$t:tt; $n:expr]) => {
        (0..$n).map(|_| __input_inner!($t)).collect::<Vec<_>>()
    };
    ([$t:tt]) => {{
        let n = __input_inner!(usize);
        (0..n).map(|_| __input_inner!($t)).collect::<Vec<_>>()
    }};
    (chars) => {
        __input_inner!(String).chars().collect::<Vec<_>>()
    };
    (bytes) => {
        __input_inner!(String).into_bytes()
    };
    (usize1) => {
        __input_inner!(usize) - 1
    };
    ($t:ty) => {
        $crate::read::<$t>()
    };
}

#[macro_export]
macro_rules! println {
    () => {
        $crate::write(|w| {
            use std::io::Write;
            std::writeln!(w).unwrap()
        })
    };
    ($($arg:tt)*) => {
        $crate::write(|w| {
            use std::io::Write;
            std::writeln!(w, $($arg)*).unwrap()
        })
    };
}

#[macro_export]
macro_rules! print {
    ($($arg:tt)*) => {
        $crate::write(|w| {
            use std::io::Write;
            std::write!(w, $($arg)*).unwrap()
        })
    };
}

#[macro_export]
macro_rules! flush {
    () => {
        $crate::write(|w| {
            use std::io::Write;
            w.flush().unwrap()
        })
    };
}

pub fn read<T>() -> T
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    use std::cell::RefCell;
    use std::io::*;

    thread_local! {
        pub static STDIN: RefCell<StdinLock<'static>> = RefCell::new(stdin().lock());
    }

    STDIN.with(|r| {
        let mut r = r.borrow_mut();
        let mut s = vec![];
        loop {
            let buf = r.fill_buf().unwrap();
            if buf.is_empty() {
                break;
            }
            if let Some(i) = buf.iter().position(u8::is_ascii_whitespace) {
                s.extend_from_slice(&buf[..i]);
                r.consume(i + 1);
                if !s.is_empty() {
                    break;
                }
            } else {
                s.extend_from_slice(buf);
                let n = buf.len();
                r.consume(n);
            }
        }
        std::str::from_utf8(&s).unwrap().parse().unwrap()
    })
}

pub fn write<F>(f: F)
where
    F: FnOnce(&mut std::io::BufWriter<std::io::StdoutLock>),
{
    use std::cell::RefCell;
    use std::io::*;

    thread_local! {
        pub static STDOUT: RefCell<BufWriter<StdoutLock<'static>>> =
            RefCell::new(BufWriter::new(stdout().lock()));
    }

    STDOUT.with(|w| f(&mut w.borrow_mut()))
}
0