Submission #62789944


Source Code Expand

#[allow(unused_imports)]
use proconio::{input, marker::Chars};

fn main() {
    input!{
        n: usize,
        s: Chars,
    }
    let mut l = 0u64;
    let mut r = 0;


    let mut cur = 0;
    {
        let mut z_cnt = 0;
        for i in 0..n {
            if s[i] == '0' {
                z_cnt += 1;
            } else {
                cur += z_cnt;
                r += 1;
            }
        }
    }

    let mut ans = INF;
    for i in 0..n {
        if s[i] == '0' {
            cur += l;
            cur -= r;
        } else if s[i] == '1' {
            r -= 1;
            ans.chmin(cur);
            l += 1;
        }
    }
    println!("{}", ans);
}

pub trait ChLibs<T: std::cmp::Ord> {
    fn chmin(&mut self, elm: T) -> bool;
    fn chmax(&mut self, elm: T) -> bool;
}

impl<T: std::cmp::Ord> ChLibs<T> for T {
    fn chmin(&mut self, elm: T) -> bool {
        if *self > elm {
            *self = elm;
            true
        } else {
            false
        }
    }

    fn chmax(&mut self, elm: T) -> bool {
        if *self < elm {
            *self = elm;
            true
        } else {
            false
        }
    }
}
pub static INF: u64 = 1e18 as u64;
pub static DI: &[usize] = &[0, !0, 0, 1, !0, 1, !0, 1];
pub static DJ: &[usize] = &[!0, 0, 1, 0, !0, !0, 1, 1];
pub static DC: &[char] = &['L', 'U', 'R', 'D'];
pub trait Debuggable {
    fn debug_string(&self) -> String;
}

impl<T: std::fmt::Debug + std::fmt::Display> Debuggable for Vec<T> {
    fn debug_string(&self) -> String {
        use itertools::Itertools;
        use std::iter::repeat;
        if let Some(max_size) = self.iter()
            .enumerate()
            .map(|(i, x)| (format!("{:?}", x).len()).max(format!("{:?}", i).len()))
            .max() {
                let mut idx = String::from("idx |");   
                let mut val = String::from("val |");   
                for (i, xi) in self.iter().enumerate() {
                    idx.push_str(
                        &format!(" {:>w$} |", i, w=max_size)
                    );
                    val.push_str(
                        &format!(" {:>w$} |", xi, w=max_size)
                    );
                }

                format!("{}\n{}\n{}\n", idx, repeat('-').take(idx.len()).join(""), val)
            } else {
                format!("idx | \nval |\n")
            }
    }
}

impl<T: std::fmt::Debug + std::fmt::Display> Debuggable for std::collections::BTreeSet<T> {
    fn debug_string(&self) -> String {
        use itertools::Itertools;
        format!("{{ {} }}", self.iter().join(", "))
    }
}

impl<T, U> Debuggable for std::collections::BTreeMap<T, U> 
where T: std::fmt::Debug + std::fmt::Display, U: std::fmt::Debug + std::fmt::Display
{
    fn debug_string(&self) -> String {
        use itertools::Itertools;
        format!(
            "{{\n{}\n }}", self.iter()
                .map(|(k, v)| format!("{k} -> {v}, "))
                .join("\n")
        )
    }
}

// lg! マクロの定義
#[macro_export]
macro_rules! lg {
    ($val:expr) => {
        #[cfg(feature = "local")]
        {
            {
                use Debuggable;
                let val = &$val;
                eprintln!(
                    "[{}:{}] {} = \n{}",
                    file!(),
                    line!(),
                    stringify!($val),
                    val.debug_string()
                );
                val
            }
        }
    }
}
    

Submission Info

Submission Time
Task D - Swap to Gather
User ardRiriy
Language Rust (rustc 1.70.0)
Score 425
Code Size 3448 Byte
Status AC
Exec Time 5 ms
Memory 4304 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 425 / 425
Status
AC × 3
AC × 28
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 02_random2_00.txt, 02_random2_01.txt, 02_random2_02.txt, 02_random2_03.txt, 02_random2_04.txt, 02_random2_05.txt, 03_handmade_00.txt, 03_handmade_01.txt, 03_handmade_02.txt, 03_handmade_03.txt, 03_handmade_04.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 2076 KiB
00_sample_01.txt AC 1 ms 1800 KiB
00_sample_02.txt AC 1 ms 1784 KiB
01_random_00.txt AC 1 ms 2192 KiB
01_random_01.txt AC 5 ms 4072 KiB
01_random_02.txt AC 4 ms 3388 KiB
01_random_03.txt AC 4 ms 4208 KiB
01_random_04.txt AC 4 ms 4228 KiB
01_random_05.txt AC 4 ms 4252 KiB
01_random_06.txt AC 5 ms 4256 KiB
01_random_07.txt AC 5 ms 4260 KiB
01_random_08.txt AC 5 ms 4252 KiB
01_random_09.txt AC 5 ms 4112 KiB
01_random_10.txt AC 5 ms 4304 KiB
01_random_11.txt AC 5 ms 4228 KiB
01_random_12.txt AC 4 ms 4180 KiB
01_random_13.txt AC 3 ms 4088 KiB
02_random2_00.txt AC 3 ms 4216 KiB
02_random2_01.txt AC 3 ms 4148 KiB
02_random2_02.txt AC 3 ms 4252 KiB
02_random2_03.txt AC 3 ms 4268 KiB
02_random2_04.txt AC 3 ms 4160 KiB
02_random2_05.txt AC 3 ms 4256 KiB
03_handmade_00.txt AC 1 ms 1964 KiB
03_handmade_01.txt AC 1 ms 1936 KiB
03_handmade_02.txt AC 1 ms 2044 KiB
03_handmade_03.txt AC 1 ms 1852 KiB
03_handmade_04.txt AC 3 ms 4224 KiB