Submission #71992144
Source Code Expand
#![allow(unused)]
use std::collections::HashMap;
use proconio::{input, marker::Chars};
fn main() {
input! {
n: usize,
k: usize,
s: Chars,
}
// 001000101001
// ------
// ^ ^ ^
let ok = |m: usize| -> bool {
let mut mark = vec![false; n];
let mut cnt = 0;
for i in 0..n {
// insert s[i]
if s[i] == '0' {
if i >= 1 && s[i - 1] == s[i] {
// segment continues
mark[i - 1] = false;
mark[i] = true;
} else {
// new segment
mark[i] = true;
cnt += 1;
}
}
// remove s[i - m]
if i >= m && s[i - m] == '0' {
if mark[i - m] {
cnt -= 1;
}
}
// check
if i >= m - 1 && cnt <= k {
return true;
}
}
false
};
// for i in 1..=n.min(10) {
// println!("{}: {}", i, ok(i));
// }
// 1 1 1 0 0 0
// ^
let mut lb = 1;
let mut ub = n;
if ok(ub) {
println!("{ub}");
return;
}
while ub - lb > 1 {
let m = (lb + ub) / 2;
if ok(m) {
lb = m;
} else {
ub = m;
}
}
println!("{lb}");
}
fn join<T: ToString>(arr: &[T], sep: &str) -> String {
arr.iter()
.map(|x| x.to_string())
.collect::<Vec<String>>()
.join(sep)
}
Submission Info
| Submission Time | |
|---|---|
| Task | D - Handstand |
| User | amoshuangyc |
| Language | Rust (rustc 1.89.0) |
| Score | 400 |
| Code Size | 1664 Byte |
| Status | AC |
| Exec Time | 16 ms |
| Memory | 2516 KiB |
Judge Result
| Set Name | All | Sample | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 400 / 400 | 0 / 0 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| All | sample_01, sample_02, sample_03, testcase_01, testcase_02, testcase_03, testcase_04, testcase_05, testcase_06, testcase_07, testcase_08, testcase_09, testcase_10, testcase_11, testcase_12, testcase_13, testcase_14, testcase_15 |
| Sample | sample_01, sample_02, sample_03 |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| sample_01 | AC | 1 ms | 1984 KiB |
| sample_02 | AC | 1 ms | 1960 KiB |
| sample_03 | AC | 1 ms | 2008 KiB |
| testcase_01 | AC | 1 ms | 2212 KiB |
| testcase_02 | AC | 2 ms | 2160 KiB |
| testcase_03 | AC | 16 ms | 2460 KiB |
| testcase_04 | AC | 1 ms | 1976 KiB |
| testcase_05 | AC | 4 ms | 2416 KiB |
| testcase_06 | AC | 3 ms | 2516 KiB |
| testcase_07 | AC | 4 ms | 2440 KiB |
| testcase_08 | AC | 4 ms | 2416 KiB |
| testcase_09 | AC | 4 ms | 2516 KiB |
| testcase_10 | AC | 4 ms | 2472 KiB |
| testcase_11 | AC | 2 ms | 2204 KiB |
| testcase_12 | AC | 2 ms | 2076 KiB |
| testcase_13 | AC | 1 ms | 2372 KiB |
| testcase_14 | AC | 1 ms | 2468 KiB |
| testcase_15 | AC | 1 ms | 2080 KiB |