Submission #44704935


Source Code Expand

use itertools::Itertools;
use memoise::memoise;
use proconio::input;

fn main() {
    input! {
        n : usize,
        m : usize
    }

    let mut c = vec![];
    let mut s = vec![];

    for _ in 0..n {
        input! { ci : f64, si : [usize] }
        c.push(ci);
        s.push(si);
    }

    for i in 0..n {
        c[i] *= s[i].len() as f64;
        s[i] = s[i].iter().filter(|&&s| s != 0).cloned().collect_vec();
        c[i] /= s[i].len() as f64;
    }

    let ans = dp(m, &c, &s);
    println!("{}", ans);
}

#[memoise(m)]
fn dp(m:usize, c:&Vec<f64>, s:&Vec<Vec<usize>>) -> f64 {
    if m <= 0 { return 0.0; }

    let mut res = f64::MAX;

    for i in 0..c.len() {
        let mut e = c[i];
        for &sj in s[i].iter() {
            e += dp(m.saturating_sub(sj), c, s) / s[i].len() as f64;
        }

        res = res.min(e);
    }

    res
}

Submission Info

Submission Time
Task E - Roulettes
User zeronosu77108
Language Rust (rustc 1.70.0)
Score 475
Code Size 906 Byte
Status AC
Exec Time 3 ms
Memory 2296 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 475 / 475
Status
AC × 3
AC × 29
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 02_handmade_25.txt, 02_handmade_26.txt, 02_handmade_27.txt, 02_handmade_28.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 2176 KiB
00_sample_01.txt AC 1 ms 1996 KiB
00_sample_02.txt AC 0 ms 1984 KiB
01_random_03.txt AC 3 ms 2156 KiB
01_random_04.txt AC 3 ms 2164 KiB
01_random_05.txt AC 3 ms 2140 KiB
01_random_06.txt AC 3 ms 2296 KiB
01_random_07.txt AC 1 ms 2116 KiB
01_random_08.txt AC 1 ms 2136 KiB
01_random_09.txt AC 1 ms 2056 KiB
01_random_10.txt AC 2 ms 2180 KiB
01_random_11.txt AC 3 ms 2160 KiB
01_random_12.txt AC 2 ms 2224 KiB
01_random_13.txt AC 3 ms 2036 KiB
01_random_14.txt AC 3 ms 2172 KiB
01_random_15.txt AC 3 ms 2172 KiB
01_random_16.txt AC 3 ms 2100 KiB
01_random_17.txt AC 3 ms 2044 KiB
01_random_18.txt AC 3 ms 2128 KiB
01_random_19.txt AC 3 ms 2108 KiB
01_random_20.txt AC 3 ms 2208 KiB
01_random_21.txt AC 3 ms 2168 KiB
01_random_22.txt AC 3 ms 2156 KiB
01_random_23.txt AC 2 ms 2176 KiB
01_random_24.txt AC 2 ms 2136 KiB
02_handmade_25.txt AC 1 ms 2028 KiB
02_handmade_26.txt AC 3 ms 2048 KiB
02_handmade_27.txt AC 1 ms 2128 KiB
02_handmade_28.txt AC 1 ms 2092 KiB