結果
| 問題 |
No.2890 Chiffon
|
| コンテスト | |
| ユーザー |
naut3
|
| 提出日時 | 2024-09-13 22:58:01 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,725 bytes |
| コンパイル時間 | 14,775 ms |
| コンパイル使用メモリ | 402,160 KB |
| 実行使用メモリ | 13,888 KB |
| 最終ジャッジ日時 | 2024-09-13 22:58:29 |
| 合計ジャッジ時間 | 19,620 ms |
|
ジャッジサーバーID (参考情報) |
judge6 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 TLE * 1 -- * 32 |
ソースコード
#![allow(non_snake_case)]
#[allow(unused_imports)]
use proconio::{fastout, input, marker::*};
#[fastout]
fn main() {
input! {
N: usize, K: usize,
A: [usize; K],
}
let mut B = A
.iter()
.cloned()
.collect::<std::collections::BTreeSet<usize>>();
for a in A.iter() {
B.insert(a + 2 * N);
}
let mut ok = 1;
let mut ng = N;
while ng - ok > 1 {
let m = ((ok + ng) / 2) * 2;
let mut nxt = vec![0u32; 4 * N + 1];
nxt[4 * N] = 4 * N as u32;
for i in (0..4 * N).step_by(2) {
// i + m がok か
if i + m < 4 * N && B.range(i + 1..i + m).next().is_some() {
nxt[i] = if m % 2 == 0 {
(i + m) as u32
} else {
(i + m + 1) as u32
};
} else {
let n = B.range(i + m..).next();
if let Some(&n) = n {
nxt[i] = (n + 1) as u32;
} else {
nxt[i] = (4 * N) as u32;
}
}
}
// eprintln!(
// "{} | {}",
// m,
// nxt.iter()
// .map(|x| x.to_string())
// .collect::<Vec<_>>()
// .join(" ")
// );
let dbl = Doubling::build(&nxt, 21);
let mut isok = false;
for i in (0..2 * N).step_by(2) {
let n = dbl.next(i as u32, K as u64);
if n <= (i + 2 * N) as u32 {
isok = true;
break;
}
}
if isok {
ok = m / 2;
} else {
ng = m / 2;
}
}
println!("{}", ok * 2);
}
pub type Index = u32;
pub struct Doubling {
dp: Vec<Index>,
pub size: usize,
pub depth: Index,
}
impl Doubling {
pub fn build(nxt: &[Index], depth: Index) -> Self {
let size = nxt.len();
let mut dp = nxt.to_vec();
dp.append(&mut vec![0; size * depth as usize]);
for d in 0..depth as usize {
for i in 0..size {
dp[(d + 1) * size + i] = dp[d * size + dp[d * size + i] as usize];
}
}
Self { dp, size, depth }
}
pub fn next(&self, mut src: Index, k: u64) -> Index {
assert!(k < 1 << (self.depth + 1));
for i in 0..self.depth {
if (k >> i) & 1 == 1 {
src = self.dp[i as usize * self.size + src as usize];
}
}
src
}
pub fn jump_power_of_two(&self, src: Index, k: Index) -> Index {
assert!(k <= self.depth);
self.dp[k as usize * self.size + src as usize]
}
}
naut3