結果

問題 No.2389 Cheating Code Golf
ユーザー 👑 MizarMizar
提出日時 2023-07-09 17:48:37
言語 Rust
(1.77.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 2,663 bytes
コンパイル時間 3,033 ms
コンパイル使用メモリ 155,216 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-10 01:14:25
合計ジャッジ時間 4,621 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,356 KB
testcase_01 AC 1 ms
4,356 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 4 ms
4,352 KB
testcase_04 AC 5 ms
4,348 KB
testcase_05 AC 1 ms
4,352 KB
testcase_06 AC 1 ms
4,352 KB
testcase_07 AC 1 ms
4,352 KB
testcase_08 AC 2 ms
4,352 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 1 ms
4,352 KB
testcase_12 AC 1 ms
4,352 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 1 ms
4,356 KB
testcase_16 AC 2 ms
4,352 KB
testcase_17 AC 1 ms
4,352 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 1 ms
4,348 KB
testcase_22 AC 1 ms
4,352 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 1 ms
4,356 KB
testcase_25 AC 1 ms
4,352 KB
testcase_26 AC 1 ms
4,356 KB
testcase_27 AC 2 ms
4,352 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 1 ms
4,348 KB
testcase_30 AC 2 ms
4,352 KB
testcase_31 AC 1 ms
4,348 KB
testcase_32 AC 1 ms
4,352 KB
testcase_33 AC 1 ms
4,352 KB
testcase_34 AC 2 ms
4,352 KB
testcase_35 AC 1 ms
4,372 KB
testcase_36 AC 2 ms
4,352 KB
testcase_37 AC 1 ms
4,348 KB
testcase_38 AC 3 ms
4,352 KB
testcase_39 AC 1 ms
4,372 KB
testcase_40 AC 1 ms
4,352 KB
testcase_41 AC 2 ms
4,352 KB
testcase_42 AC 1 ms
4,352 KB
testcase_43 AC 1 ms
4,352 KB
testcase_44 AC 1 ms
4,356 KB
testcase_45 AC 3 ms
4,352 KB
testcase_46 AC 2 ms
4,352 KB
testcase_47 AC 1 ms
4,352 KB
testcase_48 AC 1 ms
4,348 KB
testcase_49 AC 2 ms
4,352 KB
testcase_50 AC 1 ms
4,352 KB
testcase_51 AC 1 ms
4,352 KB
testcase_52 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

fn solve(n: usize, m: usize, abp: &Vec<(u32, u32, u32)>) -> f64 {
    let full_bit = (1usize << n) - 1;
    let abpp = abp
        .iter()
        .map(|&(a, b, p)| {
            (
                1f64 / (a as f64),
                1f64 / (b as f64),
                1f64 / (p as f64),
                1f64 - 1f64 / (p as f64),
            )
        })
        .collect::<Vec<_>>();
    let mut dp = [-f64::INFINITY; 4096];
    for _ in 0..=m {
        let mut dpc = dp;
        dpc[0] = 0f64;
        for i in 1..=n {
            let mut bidx = (1 << i) - 1;
            while bidx <= full_bit {
                let mut point = 0f64;
                let mut pit = bidx;
                while pit > 0 {
                    let pidx = pit.trailing_zeros() as usize;
                    let pbit = pit & pit.wrapping_neg();
                    let dpidx = bidx ^ pbit;
                    let (af, bf, psucc, pfail) = abpp[pidx];
                    point
                        .chmax((dpc[dpidx] + af).max((dpc[dpidx] + bf) * psucc + dp[bidx] * pfail));
                    pit &= pit.wrapping_sub(1);
                }
                dpc[bidx].chmax(point);
                bidx = bidx.next_combination();
            }
        }
        dp = dpc;
    }
    dp[full_bit]
}

fn main() {
    let mut stdinlock = std::io::stdin().lock();
    let mut lines = std::io::BufRead::lines(&mut stdinlock).map_while(Result::ok);
    let (n, m) = {
        let s = lines.next().unwrap();
        let mut t = s.split_ascii_whitespace();
        (
            t.next().unwrap().parse::<usize>().unwrap(),
            t.next().unwrap().parse::<usize>().unwrap(),
        )
    };
    let abp = (0..n)
        .map(|_| {
            let s = lines.next().unwrap();
            let mut t = s.split_ascii_whitespace();
            (
                t.next().unwrap().parse::<u32>().unwrap(),
                t.next().unwrap().parse::<u32>().unwrap(),
                t.next().unwrap().parse::<u32>().unwrap(),
            )
        })
        .collect::<Vec<_>>();
    println!("{}", solve(n, m, &abp));
}

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;
        }
    }
}

trait NextCombBits {
    fn next_combination(self) -> Self;
}
impl NextCombBits for usize {
    fn next_combination(self) -> Self {
        let t = self.wrapping_add(self & self.wrapping_neg());
        (((self & !t) >> self.trailing_zeros()) >> 1) | t
    }
}
0