結果

問題 No.870 無敵囲い
ユーザー phsplsphspls
提出日時 2020-01-06 23:27:31
言語 Rust
(1.77.0)
結果
AC  
実行時間 2 ms / 300 ms
コード長 1,517 bytes
コンパイル時間 811 ms
コンパイル使用メモリ 149,904 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-11 16:29:05
合計ジャッジ時間 1,759 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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