結果
| 問題 | No.3114 0→1 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-04-18 21:38:49 |
| 言語 | Rust (1.99.0 + proconio + num + itertools + ACL) |
| 結果 |
WJ
不安定
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,168 bytes |
| 記録 | |
| 最終ジャッジ日時 | 2026-10-16 03:20:19 |
|
ジャッジサーバーID (参考情報) |
judge4_0 / judge2_0 |
(要ログイン)
ソースコード
#![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}");
}