結果
問題 | No.870 無敵囲い |
ユーザー |
|
提出日時 | 2020-01-06 23:27:31 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 1 ms / 300 ms |
コード長 | 1,517 bytes |
コンパイル時間 | 11,773 ms |
コンパイル使用メモリ | 404,184 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-29 06:36:32 |
合計ジャッジ時間 | 12,713 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 18 |
ソースコード
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);}