AtCoder Beginner Contest 267 B

https://atcoder.jp/contests/abc267/tasks/abc267_b

効率が悪いですが、順番を追ってやれば問題ないですね。

// Split?
#![allow(non_snake_case)]

fn read<T: std::str::FromStr>() -> T {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).ok();
    line.trim().parse().ok().unwrap()
}

fn is_split(bs: &Vec<bool>) -> bool {
    if bs[0] {
        return false
    }
    
    // 各列にピンがあるか
    let mut exists: Vec<bool> = (0..7).map(|_| false).collect();
    let cs: Vec<usize> = vec![3, 2, 4, 1, 3, 5, 0, 2, 4, 6];
    for (i, &c) in cs.iter().enumerate() {
        if bs[i] {
            exists[c] = true
        }
    }
    
    // ピンが無い列に対して、その両側にピンがある列があるか
    for c in 1..6 {
        if !exists[c] {
            if (0..c).any(|j| exists[j]) && ((c+1)..7).any(|j| exists[j]) {
                return true
            }
        }
    }
    return false
}

fn main() {
    let S: String = read();
    let bs = S.chars().map(|c| c == '1').collect();     // 各ピンが立っているか
    
    println!("{}", if is_split(&bs) { "Yes" } else { "No" })
}