結果

問題 No.3114 0→1
ユーザー rhoo
提出日時 2025-04-18 21:38:49
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 1,168 bytes
コンパイル時間 13,353 ms
コンパイル使用メモリ 383,260 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-04-18 21:39:04
合計ジャッジ時間 14,780 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused variable: `n`
 --> src/main.rs:9:9
  |
9 |         n:usize,
  |         ^ help: if this is intentional, prefix it with an underscore: `_n`
  |
  = note: `#[warn(unused_variables)]` on by default

ソースコード

diff #

#![allow(unused_imports,non_snake_case,dead_code)]
use std::{cmp::Reverse as Rev,collections::*,iter::*};
use proconio::{marker::*,*};


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

    const INF:i64=i64::MAX/64;
    let mut dp=[INF;8];
    dp[7]=0;

    for &c in &s{
        let c=(c as u8-'0' as u8) as usize;
        let mut new=[INF;8];
        for bit in 0..8{
            let next=(bit<<1&7)+c;
            let cur=dp[bit];
            
            if next==0b000 || next==0b001{
                assert!(cur==INF);
            }
            // assert!(next!=0b000 && next!=0b001);

            let mut apply=|a:usize,add:i64|{
                new[a]=new[a].min(cur+add);
            };

            match next{
                0b010=>{
                    apply(next^1,1);
                    apply(next^4,1);
                },
                0b100=>{
                    apply(next^1,1);
                    apply(next^2,1);
                },
                _=>{
                    apply(next,0);
                }
            }
        }
        dp=new;
    }

    let ans=dp.iter().min().unwrap();
    println!("{ans}");
}
0