Submission #62071072


Source Code Expand

#[allow(unused_imports)]
use proconio::{input, marker::Usize1};

fn dp(key: i64, x: usize, v: &Vec<(i64, usize)>) -> usize {
    let mut dp = vec![-1; x+1];
    dp[0] = 0;
    for &(a, c) in v {
        for i in (0..x+1).rev() {
            if i+c >= x+1 {
                continue;
            }
            let val = dp[i] + a;
            dp[i+c].chmax(val);
        }
    }
    // key以上で最小のindex
    for (i, &xi) in dp.iter().enumerate() {
        if xi >= key {
            return i;
        }
    }
    return x+1;
}

fn main() {
    input!{
        n: usize,
        x: usize,
        v: [(Usize1, i64, usize); n],
    }
 
    let v = v.iter().fold(vec![vec![]; 3], |mut v, &(i, a, c)| {
        v[i].push((a, c));
        v
    });


    let mut ok = 0;
    let mut ng = 1e18 as i64;
    // let mut ng = 10;
    while ng-ok>1 {
        let mid = (ok+ng)/2;
        let s = (0..3).into_iter().map(|i| {
            let res = dp(mid, x, &v[i]);
            res
        }).sum::<usize>();

        if s <= x {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    println!("{}", ok);
}

pub trait ChLibs<T: std::cmp::Ord> {
    fn chmin(&mut self, elm: T) -> bool;
    fn chmax(&mut self, elm: T) -> bool;
}

impl<T: std::cmp::Ord> ChLibs<T> for T {
    fn chmin(&mut self, elm: T) -> bool {
        if *self > elm {
            *self = elm;
            true
        } else {
            false
        }
    }

    fn chmax(&mut self, elm: T) -> bool {
        if *self < elm {
            *self = elm;
            true
        } else {
            false
        }
    }
}
pub trait Debuggable {
    fn debug_string(&self) -> String;
}

impl<T: std::fmt::Debug + std::fmt::Display> Debuggable for Vec<T> {
    fn debug_string(&self) -> String {
        use itertools::Itertools;
        use std::iter::repeat;
        if let Some(max_size) = self.iter()
            .enumerate()
            .map(|(i, x)| (format!("{:?}", x).len()).max(format!("{:?}", i).len()))
            .max() {
                let mut idx = String::from("idx |");   
                let mut val = String::from("val |");   
                for (i, xi) in self.iter().enumerate() {
                    idx.push_str(
                        &format!(" {:>w$} |", i, w=max_size)
                    );
                    val.push_str(
                        &format!(" {:>w$} |", xi, w=max_size)
                    );
                }

                format!("{}\n{}\n{}\n", idx, repeat('-').take(idx.len()).join(""), val)
            } else {
                format!("idx | \nval |\n")
            }
    }
}

impl<T: std::fmt::Debug + std::fmt::Display> Debuggable for std::collections::BTreeSet<T> {
    fn debug_string(&self) -> String {
        use itertools::Itertools;
        format!("{{ {} }}", self.iter().join(", "))
    }
}

impl<T, U> Debuggable for std::collections::BTreeMap<T, U> 
where T: std::fmt::Debug + std::fmt::Display, U: std::fmt::Debug + std::fmt::Display
{
    fn debug_string(&self) -> String {
        use itertools::Itertools;
        format!(
            "{{\n{}\n }}", self.iter()
                .map(|(k, v)| format!("{k} -> {v}, "))
                .join("\n")
        )
    }
}

// lg! マクロの定義
#[macro_export]
macro_rules! lg {
    ($val:expr) => {
        #[cfg(feature = "local")]
        {
            {
                use Debuggable;
                let val = &$val;
                eprintln!(
                    "[{}:{}] {} = \n{}",
                    file!(),
                    line!(),
                    stringify!($val),
                    val.debug_string()
                );
                val
            }
        }
    }
}
    

Submission Info

Submission Time
Task E - Vitamin Balance
User ardRiriy
Language Rust (rustc 1.70.0)
Score 450
Code Size 3714 Byte
Status AC
Exec Time 1653 ms
Memory 2264 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 450 / 450
Status
AC × 2
AC × 58
Set Name Test Cases
Sample example_00.txt, example_01.txt
All example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, hand_10.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, random_33.txt, random_34.txt, random_35.txt, random_36.txt, random_37.txt, random_38.txt, random_39.txt, random_40.txt, random_41.txt, random_42.txt, random_43.txt, random_44.txt
Case Name Status Exec Time Memory
example_00.txt AC 0 ms 1804 KiB
example_01.txt AC 2 ms 1912 KiB
hand_00.txt AC 0 ms 1836 KiB
hand_01.txt AC 848 ms 2224 KiB
hand_02.txt AC 2 ms 1976 KiB
hand_03.txt AC 971 ms 2264 KiB
hand_04.txt AC 5 ms 1828 KiB
hand_05.txt AC 0 ms 1740 KiB
hand_06.txt AC 1502 ms 2204 KiB
hand_07.txt AC 445 ms 2252 KiB
hand_08.txt AC 1 ms 2092 KiB
hand_09.txt AC 0 ms 1940 KiB
hand_10.txt AC 1653 ms 2180 KiB
random_00.txt AC 11 ms 1908 KiB
random_01.txt AC 11 ms 2128 KiB
random_02.txt AC 7 ms 2136 KiB
random_03.txt AC 15 ms 2056 KiB
random_04.txt AC 15 ms 1844 KiB
random_05.txt AC 9 ms 1968 KiB
random_06.txt AC 25 ms 1960 KiB
random_07.txt AC 59 ms 1980 KiB
random_08.txt AC 14 ms 2128 KiB
random_09.txt AC 85 ms 1984 KiB
random_10.txt AC 105 ms 2008 KiB
random_11.txt AC 133 ms 1960 KiB
random_12.txt AC 500 ms 2080 KiB
random_13.txt AC 454 ms 2224 KiB
random_14.txt AC 510 ms 2128 KiB
random_15.txt AC 17 ms 2112 KiB
random_16.txt AC 15 ms 1984 KiB
random_17.txt AC 10 ms 1848 KiB
random_18.txt AC 3 ms 1912 KiB
random_19.txt AC 13 ms 2048 KiB
random_20.txt AC 15 ms 1916 KiB
random_21.txt AC 60 ms 1916 KiB
random_22.txt AC 42 ms 2124 KiB
random_23.txt AC 20 ms 1832 KiB
random_24.txt AC 168 ms 2004 KiB
random_25.txt AC 114 ms 1996 KiB
random_26.txt AC 312 ms 1988 KiB
random_27.txt AC 786 ms 2020 KiB
random_28.txt AC 953 ms 2056 KiB
random_29.txt AC 378 ms 2120 KiB
random_30.txt AC 11 ms 1964 KiB
random_31.txt AC 12 ms 1980 KiB
random_32.txt AC 12 ms 2104 KiB
random_33.txt AC 12 ms 1960 KiB
random_34.txt AC 4 ms 1880 KiB
random_35.txt AC 8 ms 1952 KiB
random_36.txt AC 9 ms 2000 KiB
random_37.txt AC 39 ms 1976 KiB
random_38.txt AC 55 ms 1980 KiB
random_39.txt AC 21 ms 2124 KiB
random_40.txt AC 100 ms 2124 KiB
random_41.txt AC 62 ms 2108 KiB
random_42.txt AC 1007 ms 2168 KiB
random_43.txt AC 1379 ms 2132 KiB
random_44.txt AC 91 ms 2176 KiB