結果

問題 No.240 ナイト散歩
コンテスト
ユーザー tonyu0
提出日時 2020-04-29 01:38:27
言語 Rust
(1.94.0 + proconio + num + itertools)
コンパイル:
/usr/bin/rustc_custom
実行:
./target/release/main
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 893 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,285 ms
コンパイル使用メモリ 187,680 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-05-20 19:26:00
合計ジャッジ時間 2,689 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

use std::io::*;

fn dfs(list: &mut Vec<(i64, i64)>, mov: &[(i64, i64)], d: usize, cx: i64, cy: i64) {
    if d <= 3 {
        list.push((cx, cy));
        for &m in mov.iter() {
            dfs(list, &mov, d + 1, cx + m.0, cy + m.1);
        }
    }
}

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let p = (
        itr.next().unwrap().parse::<i64>().unwrap(),
        itr.next().unwrap().parse::<i64>().unwrap(),
    );

    let mov = [
        (-2, -1),
        (-2, 1),
        (-1, -2),
        (-1, 2),
        (1, -2),
        (1, 2),
        (2, -1),
        (2, 1),
    ]
    .to_vec();

    let mut list = Vec::new();
    dfs(&mut list, &mov, 0, 0, 0);
    if let Some(_) = list.iter().find(|&&x| x == p) {
        println!("YES",)
    } else {
        println!("NO",)
    }
}
0