結果

問題 No.155 生放送とBGM
ユーザー koba-e964koba-e964
提出日時 2021-09-16 21:25:33
言語 Rust
(1.77.0)
結果
AC  
実行時間 561 ms / 6,000 ms
コード長 3,289 bytes
コンパイル時間 1,376 ms
コンパイル使用メモリ 155,024 KB
実行使用メモリ 16,584 KB
最終ジャッジ日時 2023-09-12 04:14:09
合計ジャッジ時間 6,303 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 534 ms
16,576 KB
testcase_01 AC 553 ms
16,428 KB
testcase_02 AC 561 ms
16,584 KB
testcase_03 AC 561 ms
16,572 KB
testcase_04 AC 18 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 528 ms
16,424 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 5 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 7 ms
4,380 KB
testcase_12 AC 7 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 391 ms
13,472 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#[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),* )) => { ($(read_value!($next, $t)),*) };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => (read_value!($next, usize) - 1);
    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        read_value!($next, [$t; len])
    }};
    ($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 parse(s: &str) -> usize {
    let s: Vec<_> = s.split(":").collect();
    assert_eq!(s.len(), 2);
    let m: usize = s[0].parse().unwrap();
    let s: usize = s[1].parse().unwrap();
    60 * m + s
}

fn calc(l: usize, s: &[usize]) -> f64 {
    let n = s.len();
    let mut dp = vec![vec![0.0; l]; n + 1];
    dp[0][0] = 1.0;
    for i in 0..n {
        let mut ep = dp.clone();
        for u in 0..n {
            for j in 0..l {
                let val = dp[u][j];
                if u + 1 < n && j + s[i] < l {
                    ep[u + 1][j + s[i]] += val;
                }
            }
        }
        dp = ep;
    }
    let mut comb = vec![vec![0.0; n + 1]; n + 1];
    comb[0][0] = 1.0;
    for i in 1..n + 1 {
        for j in 0..n + 1 {
            comb[i][j] = comb[i - 1][j];
            if j > 0 {
                comb[i][j] += comb[i - 1][j - 1];
            }
        }
    }
    let mut ans = 0.0;
    let mut tmp = vec![vec![0.0; l]; n];
    for i in 0..n {
        // modosu dp (find dp values without i-th element)
        for j in 0..n {
            for k in 0..l {
                tmp[j][k] = dp[j][k];
                if j > 0 && k >= s[i] {
                    tmp[j][k] -= tmp[j - 1][k - s[i]];
                }
            }
        }
        for j in 0..n {
            for k in 0..l {
                // (* i! * (n - i - 1)! / n!) = (/ n / comb[n - 1][i])
                ans += tmp[j][k] / comb[n - 1][j];
            }
        }
    }
    ans / n as f64
}

fn main() {
    input! {
        n: usize, l: usize,
        s: [String; n],
    }
    let l = 60 * l;
    let s: Vec<_> = s.iter().map(|x| parse(x)).collect();
    let ans = calc(l, &s);
    println!("{}", ans);
}
0