QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#816703 | #127. Card Game Strategy | Qingyu | Compile Error | / | / | Rust | 2.3kb | 2024-12-16 16:56:03 | 2024-12-16 16:56:04 |
Judging History
This is the latest submission verdict.
- [2024-12-16 16:56:04]
- Judged
- Verdict: Compile Error
- Time: 0ms
- Memory: 0kb
- [2024-12-16 16:56:03]
- Submitted
answer
use itertools::*;
fn main() {
proconio::input! {
n: usize,
k: usize,
a: usize,
b: usize,
x: [usize; n],
}
let mut x = x.into_iter().enumerate().collect::<Vec<_>>();
x.sort_by_key(|p| p.1);
let min = x.iter().map(|p| p.1).take(k).sum::<usize>();
let max = x.iter().map(|p| p.1).rev().take(k).sum::<usize>();
let inf = (k + 1) as u16;
let mut dp = vec![vec![inf; max - min + 1]];
let mut pre = vec![inf; max - min + 1 + x[n - 1].1];
dp[0][0] = 0;
for (i, &(_, v)) in x[k..].iter().enumerate() {
let mut next_dp = dp[i].clone();
let mut next_pre = pre.clone();
for (next_pre, dp) in next_pre[v..].iter_mut().zip(&dp[i]) {
*next_pre = std::cmp::min(*next_pre, *dp);
}
for (i, (s, t)) in next_pre.iter().zip(pre).enumerate().filter(|(_, p)| *p.0 != inf) {
let s = *s as usize;
let t = t as usize;
for (j, &(_, x)) in x[s..k.min(t)].iter().enumerate() {
let v = (s + j + 1) as u16;
next_dp[i - x] = std::cmp::min(next_dp[i - x], v);
}
}
dp.push(next_dp);
pre = next_pre;
}
let mut d = vec![180000; 180000 + 1];
for (d, dp) in d[min..].iter_mut().zip(dp.last().unwrap()) {
if *dp < inf {
*d = 0;
}
}
for _ in 0..2 {
for i in 1..d.len() {
d[i] = d[i].min(d[i - 1] + 1);
}
d.reverse();
}
let alice = (a..=b).max_by_key(|&x| (d[x], !x)).unwrap();
let bob = if d.get(alice + 1).map_or(false, |p| *p < d[alice]) {
alice + d[alice..].iter().position(|d| *d == 0).unwrap()
} else {
alice - d[..=alice].iter().rev().position(|d| *d == 0).unwrap()
};
let mut p = (dp.len() - 1, bob - min);
let mut used = vec![true; n];
while p.0 > 0 {
if dp[p.0][p.1] == dp[p.0 - 1][p.1] {
p.0 -= 1;
used[k + p.0] = false;
continue;
}
let v = dp[p.0][p.1] as usize - 1;
used[v] = false;
p.1 = p.1 + x[v].1 - x[k + p.0 - 1].1;
p.0 -= 1;
}
x = (0..n).filter(|k| used[*k]).map(|k| x[k]).collect();
x.sort();
println!("{}", alice);
println!("{}", x.iter().map(|x| (x.0 + 1)).join(" "));
}
Details
error[E0432]: unresolved import `itertools` --> answer.code:1:5 | 1 | use itertools::*; | ^^^^^^^^^ maybe a missing crate `itertools`? | = help: consider adding `extern crate itertools` to use the `itertools` crate error[E0433]: failed to resolve: use of undeclared crate or module `proconio` --> answer.code:4:5 | 4 | proconio::input! { | ^^^^^^^^ use of undeclared crate or module `proconio` error[E0425]: cannot find value `x` in this scope --> answer.code:11:17 | 11 | let mut x = x.into_iter().enumerate().collect::<Vec<_>>(); | ^ not found in this scope error[E0425]: cannot find value `k` in this scope --> answer.code:13:42 | 13 | let min = x.iter().map(|p| p.1).take(k).sum::<usize>(); | ^ help: a tuple variant with a similar name exists: `Ok` --> /build/rustc-60UC9b/rustc-1.75.0+dfsg0ubuntu1~bpo0/library/core/src/result.rs:506:5 | = note: similarly named tuple variant `Ok` defined here error[E0425]: cannot find value `k` in this scope --> answer.code:14:48 | 14 | let max = x.iter().map(|p| p.1).rev().take(k).sum::<usize>(); | ^ help: a tuple variant with a similar name exists: `Ok` --> /build/rustc-60UC9b/rustc-1.75.0+dfsg0ubuntu1~bpo0/library/core/src/result.rs:506:5 | = note: similarly named tuple variant `Ok` defined here error[E0425]: cannot find value `k` in this scope --> answer.code:15:16 | 15 | let inf = (k + 1) as u16; | ^ help: a tuple variant with a similar name exists: `Ok` --> /build/rustc-60UC9b/rustc-1.75.0+dfsg0ubuntu1~bpo0/library/core/src/result.rs:506:5 | = note: similarly named tuple variant `Ok` defined here error[E0425]: cannot find value `n` in this scope --> answer.code:17:47 | 17 | let mut pre = vec![inf; max - min + 1 + x[n - 1].1]; | ^ help: a local variable with a similar name exists: `x` error[E0425]: cannot find value `k` in this scope --> answer.code:19:27 | 19 | for (i, &(_, v)) in x[k..].iter().enumerate() { | ^ help: a tuple variant with a similar name exists: `Ok` --> /build/rustc-60UC9b/rustc-1.75.0+dfsg0ubuntu1~bpo0/library/core/src/result.rs:506:5 | = note: similarly named tuple variant `Ok` defined here error[E0425]: cannot find value `k` in this scope --> answer.code:28:38 | 28 | for (j, &(_, x)) in x[s..k.min(t)].iter().enumerate() { | ^ --> /build/rustc-60UC9b/rustc-1.75.0+dfsg0ubuntu1~bpo0/library/core/src/result.rs:506:5 | = note: similarly named tuple variant `Ok` defined here | help: a tuple variant with a similar name exists | 28 | for (j, &(_, x)) in x[s..Ok.min(t)].iter().enumerate() { | ~~ help: you might have meant to write `.` instead of `..` | 28 - for (j, &(_, x)) in x[s..k.min(t)].iter().enumerate() { 28 + for (j, &(_, x)) in x[s.k.min(t)].iter().enumerate() { | error[E0425]: cannot find value `a` in this scope --> answer.code:48:18 | 48 | let alice = (a..=b).max_by_key(|&x| (d[x], !x)).unwrap(); | ^ help: a local variable with a similar name exists: `d` error[E0425]: cannot find value `b` in this scope --> answer.code:48:22 | 48 | let alice = (a..=b).max_by_key(|&x| (d[x], !x)).unwrap(); | ^ help: a local variable with a similar name exists: `d` error[E0425]: cannot find value `n` in this scope --> answer.code:55:31 | 55 | let mut used = vec![true; n]; | ^ help: a local variable with a similar name exists: `d` error[E0425]: cannot find value `k` in this scope --> answer.code:59:18 | 59 | used[k + p.0] = false; | ^ help: a tuple variant with a similar name exists: `Ok` --> /build/rustc-60UC9b/rustc-1.75.0+dfsg0ubuntu1~bpo0/library/core/src/result.rs:506:5 | = note: similarly named tuple variant `Ok` defined here error[E0425]: cannot find value `k` in this scope --> answer.code:64:32 | 64 | p.1 = p.1 + x[v].1 - x[k + p.0 - 1].1; | ^ help: a tuple variant with a similar name exists: `Ok` --> /build/rustc-60UC9b/rustc-1.75.0+dfsg0ubuntu1~bpo0/library/core/src/result.rs:506:5 | = note: similarly named tuple variant `Ok` defined here error[E0425]: cannot find value `n` in this scope --> answer.code:67:13 | 67 | x = (0..n).filter(|k| used[*k]).map(|k| x[k]).collect(); | ^ | help: a local variable with a similar name exists | 67 | x = (0..d).filter(|k| used[*k]).map(|k| x[k]).collect(); | ~ help: you might have meant to write `.` instead of `..` | 67 - x = (0..n).filter(|k| used[*k]).map(|k| x[k]).collect(); 67 + x = (0.n...