AtCoder Beginner Contest 274 D

https://atcoder.jp/contests/abc274/tasks/abc274_d

x軸とy軸で分けて考えればよいです。
あと、flattenがちゃんとあるんですね。

// Robot Arms 2
#![allow(non_snake_case)]

use std::collections::HashSet;

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 read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
            .map(|e| e.parse().ok().unwrap()).collect()
}

fn YesNo(b: bool) -> String {
    return if b { "Yes".to_string() } else { "No".to_string() }
}

fn read_input() -> (i32, i32, Vec<i32>) {
    let v = read_vec();
    let x = v[1];
    let y = v[2];
    let A = read_vec();
    (x, y, A)
}

fn update(s: &HashSet<i32>, d: i32) -> HashSet<i32> {
    s.iter().map(|&n| vec![n-d, n+d]).flatten().collect::<HashSet<i32>>()
}

fn f(x: i32, y: i32, A: Vec<i32>) -> bool {
    let N = A.len();
    let mut sx = (A[0]..(A[0]+1)).collect::<HashSet<i32>>();
    let mut sy = (0..1).collect::<HashSet<i32>>();
    for i in (2..N).step_by(2) {
        sx = update(&sx, A[i]);
    }
    if !sx.contains(&x) {
        return false;
    }
    for i in (1..N).step_by(2) {
        sy = update(&sy, A[i]);
    }
    return sy.contains(&y)
}

fn main() {
    let v = read_input();
    println!("{}", YesNo(f(v.0, v.1, v.2)))
}