結果

問題 No.3114 0→1
コンテスト
ユーザー zer0-star
提出日時 2025-04-19 01:22:26
言語 Rust
(1.99.0 + proconio + num + itertools + ACL)
コンパイル:
/usr/bin/rustc_custom
実行:
./target/release/main
結果
WJ  
(最新)
AC  
(最初)
実行時間 -
コード長 994 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
最終ジャッジ日時 2026-10-16 03:22:55
ジャッジサーバーID
(参考情報)
judge5_0 / judge3_0
このコードへのチャレンジ
(要ログイン)

ソースコード

diff #
raw source code

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

const DIRS: [(isize, isize); 4] = [(0, 1), (1, 0), (0, -1), (-1, 0)];

trait OrdExt {
    fn chmax(&mut self, other: Self) -> bool;
    fn chmin(&mut self, other: Self) -> bool;
}

impl<T: Ord> OrdExt for T {
    fn chmax(&mut self, other: Self) -> bool {
        if *self < other {
            *self = other;
            true
        } else {
            false
        }
    }

    fn chmin(&mut self, other: Self) -> bool {
        if *self > other {
            *self = other;
            true
        } else {
            false
        }
    }
}

#[fastout]
fn main() {
    input! {
        N: usize,
        S: Chars
    }

    let mut ans = 0;
    let mut tmp = if S[0] == '1' { 1 } else { -1 };

    for i in 1..N {
        if S[i] == '1' {
            tmp += 1;
        } else if tmp > 0 {
            tmp = -1;
        } else {
            ans += 1;
            tmp += 1;
        }
    }

    println!("{}", ans);
}
0