結果

問題 No.240 ナイト散歩
ユーザー Masaki Kitaguchi
提出日時 2022-01-11 10:31:45
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 1,490 bytes
コンパイル時間 12,995 ms
コンパイル使用メモリ 402,348 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-14 11:30:11
合計ジャッジ時間 13,739 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#[macro_export]
macro_rules! setup {
    { mut $input:ident: SplitWhitespace $(,)? } => {
        use std::io::Read;
        let mut buf = String::new();
        std::io::stdin().read_to_string(&mut buf).unwrap();
        let mut $input = buf.split_whitespace();
    };
}

#[macro_export]
macro_rules! parse_next {
    ($str_iter:expr) => {
        $str_iter.next().unwrap().parse().unwrap()
    };
}

fn main() {
    setup! { mut input: SplitWhitespace };

    let x: i64 = parse_next!(input);
    let y: i64 = parse_next!(input);

    macro_rules! walk {
        ($x:expr, $y:expr, $store:expr) => {{
            $store.push(($x - 2, $y - 1));
            $store.push(($x - 2, $y + 1));
            $store.push(($x - 1, $y - 2));
            $store.push(($x - 1, $y + 2));
            $store.push(($x + 1, $y - 2));
            $store.push(($x + 1, $y + 2));
            $store.push(($x + 2, $y - 1));
            $store.push(($x + 2, $y + 1));
        }};
    }

    let mut store = vec![];
    {
        store.push((0, 0));
    }
    for i in 0..store.len() {
        walk!(store[i].0, store[i].1, store);
    }
    for i in 1..store.len() {
        walk!(store[i].0, store[i].1, store);
    }
    for i in (1 + 8)..store.len() {
        walk!(store[i].0, store[i].1, store);
    }

    store.sort();
    store.dedup();

    let ans = match store.into_iter().find(|(x_i, y_i)| (*x_i, *y_i) == (x, y)) {
        Some(_) => "YES",
        None => "NO",
    };

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