結果

問題 No.3015 右に寄せろ!
ユーザー magurofly
提出日時 2025-01-25 13:48:34
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 15 ms / 2,000 ms
コード長 865 bytes
コンパイル時間 23,407 ms
コンパイル使用メモリ 377,920 KB
実行使用メモリ 11,776 KB
最終ジャッジ日時 2025-01-25 22:59:50
合計ジャッジ時間 14,079 ms
ジャッジサーバーID
(参考情報)
judge3 / judge11
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 36
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused variable: `NEXT_ONE`
  --> src/main.rs:30:13
   |
30 |             NEXT_ONE => {
   |             ^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_NEXT_ONE`
   |
   = note: `#[warn(unused_variables)]` on by default

ソースコード

diff #

#![allow(non_snake_case)]

use proconio::input;
use proconio::marker::Chars;

fn main() {
    input! {
        S: Chars,
    }
    let N = S.len();

    enum State {
        Start,
        NextOne,
    }
    use State::*;

    let mut ans = 0usize;
    let mut state = State::Start;
    let mut right = N;
    for i in (0 .. N).rev() {
        match state {
            Start => {
                if S[i] == '0' {
                    // none
                } else {
                    state = NextOne;
                }
            }
            NEXT_ONE => {
                if S[i] == '0' {
                    right -= 1;
                    state = Start;
                } else {
                    right -= 2;
                    ans += right - i;
                    state = Start;
                }
            }
        }
    }

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