結果

問題 No.870 無敵囲い
ユーザー phsplsphspls
提出日時 2020-01-06 23:24:55
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,517 bytes
コンパイル時間 2,942 ms
コンパイル使用メモリ 147,764 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-11 16:28:47
合計ジャッジ時間 1,924 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::Read;

struct Position {
    x: u8,
    y: u8,
}

impl Position {
    fn new(x: u8, y: u8) -> Position {
        Position {
            x: x,
            y: y,
        }
    }

    fn moving(&mut self, move_data: &Vec<u8>) {
        if move_data[0] == self.x && move_data[1] == self.y {
            self.x = move_data[2];
            self.y = move_data[3];
        }
    }

    fn equals(&self, another: &Position) -> bool {
        self.x == another.x && self.y == another.y
    }
}

fn solve(moves: Vec<Vec<u8>>) {
    let mut targets = vec![
          Position::new(2 , 8)
        , Position::new(3 , 9)
        , Position::new(7 , 9)
    ];
    moves.iter().for_each(|move_data| {
        targets.iter_mut().for_each(|t| t.moving(move_data));
    });
    let expects = vec![
          Position::new(5 , 8)
        , Position::new(4 , 8)
        , Position::new(6 , 8)
    ];
    let failed = targets.iter().zip(expects.iter()).any(|pair| !pair.0.equals(pair.1));
    if failed {
        println!("{}", "No");
    } else {
        println!("{}", "Yes");
    }
}

fn main() {
    let mut all_data = String::new();
    std::io::stdin().read_to_string(&mut all_data).ok();
    let lines: Vec<&str> = all_data.trim().split('\n').map(|s| s.trim()).collect();
    let n: u8 = lines.iter().next().unwrap().parse::<u8>().unwrap();
    let moves: Vec<Vec<u8>> = lines.iter().skip(1).take(n as usize).map(|line| line.split_whitespace().map(|w| w.parse::<u8>().unwrap()).collect()).collect();
    solve(moves);
}
0