Submission #59856274


Source Code Expand

use std::collections::HashMap;

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

pub fn main() {
    input! {
        n: usize,
        k: usize,
        s: Chars
    };
    let mut connected = -1;
    let mut map = HashMap::new();
    let mut sep = vec![];
    for i in 0..n {
        if s[i] == '1' {
            if connected == -1 {
                connected = i as i64;
                sep.push(i as i64);
            }
        } else {
            if connected != -1 {
                map.insert(connected, i as i64);
            }
            connected = -1;
        }
    }
    if connected != -1 {
        map.insert(connected, n as i64);
    }
    let mut ans = "".to_string();
    let mut count = 0;
    let mut i = 0;
    loop {
        if i == n as i64 {
            break;
        }
        if let Some(&v) = map.get(&(i as i64)) {
            count += 1;
            if count == k {
                for _ in 0..(v - i as i64) {
                    i += 1;
                }
            }
            for _ in 0..(v - i as i64) {
                ans.push('1');
                i += 1;
            }
            if count == k - 1 {
                if let Some(&v) = map.get(&(sep[k - 1])) {
                    for _ in 0..(v - sep[k - 1]) {
                        ans.push('1');
                    }
                }
            }
        } else {
            ans.push('0');
            i += 1;
        }
    }
    println!("{}", ans);
}

Submission Info

Submission Time
Task C - Move Segment
User macaroon
Language Rust (rustc 1.70.0)
Score 300
Code Size 1505 Byte
Status AC
Exec Time 41 ms
Memory 19184 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 2
AC × 28
Set Name Test Cases
Sample sample_01.txt, sample_02.txt
All min.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, sample_01.txt, sample_02.txt
Case Name Status Exec Time Memory
min.txt AC 1 ms 2064 KiB
random_01.txt AC 39 ms 19184 KiB
random_02.txt AC 41 ms 18988 KiB
random_03.txt AC 4 ms 4676 KiB
random_04.txt AC 8 ms 4772 KiB
random_05.txt AC 6 ms 4720 KiB
random_06.txt AC 9 ms 5920 KiB
random_07.txt AC 1 ms 2116 KiB
random_08.txt AC 6 ms 4792 KiB
random_09.txt AC 2 ms 2340 KiB
random_10.txt AC 9 ms 5840 KiB
random_11.txt AC 6 ms 4796 KiB
random_12.txt AC 6 ms 4792 KiB
random_13.txt AC 1 ms 2160 KiB
random_14.txt AC 9 ms 5796 KiB
random_15.txt AC 1 ms 2264 KiB
random_16.txt AC 6 ms 4760 KiB
random_17.txt AC 7 ms 4772 KiB
random_18.txt AC 10 ms 5928 KiB
random_19.txt AC 6 ms 4664 KiB
random_20.txt AC 6 ms 4680 KiB
random_21.txt AC 2 ms 2984 KiB
random_22.txt AC 9 ms 5776 KiB
random_23.txt AC 2 ms 2944 KiB
random_24.txt AC 6 ms 4724 KiB
random_25.txt AC 5 ms 4220 KiB
sample_01.txt AC 1 ms 2072 KiB
sample_02.txt AC 0 ms 1852 KiB