結果

問題 No.3114 0→1
コンテスト
ユーザー zer0-star
提出日時 2025-04-19 01:22:26
言語 Rust
(1.94.0 + proconio + num + itertools)
コンパイル:
/usr/bin/rustc_custom
実行:
./target/release/main
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 994 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 10,684 ms
コンパイル使用メモリ 199,012 KB
実行使用メモリ 9,160 KB
最終ジャッジ日時 2026-07-09 21:06:32
合計ジャッジ時間 10,273 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused import: `Usize1`
 --> src/main.rs:3:21
  |
3 |     marker::{Chars, Usize1},
  |                     ^^^^^^
  |
  = note: `#[warn(unused_imports)]` (part of `#[warn(unused)]`) on by default

warning: constant `DIRS` is never used
 --> src/main.rs:6:7
  |
6 | const DIRS: [(isize, isize); 4] = [(0, 1), (1, 0), (0, -1), (-1, 0)];
  |       ^^^^
  |
  = note: `#[warn(dead_code)]` (part of `#[warn(unused)]`) on by default

warning: trait `OrdExt` is never used
 --> src/main.rs:8:7
  |
8 | trait OrdExt {
  |       ^^^^^^

warning: variable `N` should have a snake case name
  --> src/main.rs:36:9
   |
36 |         N: usize,
   |         ^ help: convert the identifier to snake case: `n`
   |
   = note: `#[warn(non_snake_case)]` (part of `#[warn(nonstandard_style)]`) on by default

warning: variable `S` should have a snake case name
  --> src/main.rs:37:9
   |
37 |         S: Chars
   |         ^ help: convert the identifier to snake case (notice the capitalization): `s`

ソースコード

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