提出 #32832563


ソースコード 拡げる

use proconio::{input, marker::Chars};

fn main() {
    input! {
        n: usize,
        k: usize,
        s: Chars,
    };

    let a = {
        let mut a = if s[0] == '0' { vec![('1', 0)] } else { vec![] };
        let mut p = s[0];
        let mut c = 1;
        for s_i in s.iter().copied().skip(1) {
            if p != s_i {
                a.push((p, c));
                p = s_i;
                c = 1;
            } else {
                c += 1;
            }
        }
        a.push((p, c));
        if p == '0' {
            a.push(('1', 0));
        }
        a
    };

    let zero_count = a.iter().filter(|(s_i, _)| *s_i == '0').count();
    if zero_count <= k {
        println!("{}", n);
        return;
    }

    let m = a.len();
    let mut sum = a[0].1;
    let mut max = sum;
    let mut r = 1;
    for l in (0..m).step_by(2) {
        while r < m && (r + 1 - l) / 2 <= k {
            sum += a[r].1;
            sum += a[r + 1].1;
            r += 2;
        }
        max = max.max(sum);
        if r == l {
            r += 2;
        } else {
            sum -= a[l].1;
            if l + 1 < m {
                sum -= a[l + 1].1;
            }
        }
    }
    let ans = max;
    println!("{}", ans);
}

提出情報

提出日時
問題 D - Handstand
ユーザ bouzuya
言語 Rust (1.42.0)
得点 400
コード長 1237 Byte
結果 AC
実行時間 7 ms
メモリ 3436 KiB

ジャッジ結果

セット名 All Sample
得点 / 配点 400 / 400 0 / 0
結果
AC × 18
AC × 3
セット名 テストケース
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
ケース名 結果 実行時間 メモリ
sample_01 AC 7 ms 2136 KiB
sample_02 AC 1 ms 2100 KiB
sample_03 AC 1 ms 2032 KiB
testcase_01 AC 2 ms 2208 KiB
testcase_02 AC 2 ms 2188 KiB
testcase_03 AC 4 ms 2888 KiB
testcase_04 AC 1 ms 2064 KiB
testcase_05 AC 4 ms 3436 KiB
testcase_06 AC 3 ms 3424 KiB
testcase_07 AC 4 ms 3144 KiB
testcase_08 AC 4 ms 3140 KiB
testcase_09 AC 7 ms 3112 KiB
testcase_10 AC 2 ms 2344 KiB
testcase_11 AC 2 ms 2220 KiB
testcase_12 AC 2 ms 2192 KiB
testcase_13 AC 2 ms 2468 KiB
testcase_14 AC 2 ms 2452 KiB
testcase_15 AC 1 ms 2060 KiB