結果
| 問題 |
No.2389 Cheating Code Golf
|
| コンテスト | |
| ユーザー |
👑 |
| 提出日時 | 2023-07-09 17:48:37 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 5 ms / 2,000 ms |
| コード長 | 2,663 bytes |
| コンパイル時間 | 14,852 ms |
| コンパイル使用メモリ | 387,072 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-09-12 23:43:11 |
| 合計ジャッジ時間 | 15,107 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 50 |
ソースコード
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
}
}