結果
問題 | No.228 ゆきこちゃんの 15 パズル |
ユーザー | kei |
提出日時 | 2018-09-10 15:25:01 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 1 ms / 5,000 ms |
コード長 | 3,989 bytes |
コンパイル時間 | 13,322 ms |
コンパイル使用メモリ | 391,624 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-09 10:54:25 |
合計ジャッジ時間 | 14,338 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,816 KB |
testcase_01 | AC | 1 ms
6,816 KB |
testcase_02 | AC | 1 ms
6,940 KB |
testcase_03 | AC | 1 ms
6,940 KB |
testcase_04 | AC | 1 ms
6,940 KB |
testcase_05 | AC | 1 ms
6,940 KB |
testcase_06 | AC | 1 ms
6,940 KB |
testcase_07 | AC | 1 ms
6,940 KB |
testcase_08 | AC | 1 ms
6,944 KB |
testcase_09 | AC | 1 ms
6,940 KB |
testcase_10 | AC | 1 ms
6,940 KB |
testcase_11 | AC | 1 ms
6,944 KB |
testcase_12 | AC | 1 ms
6,940 KB |
testcase_13 | AC | 1 ms
6,940 KB |
testcase_14 | AC | 0 ms
6,940 KB |
testcase_15 | AC | 1 ms
6,940 KB |
testcase_16 | AC | 1 ms
6,940 KB |
testcase_17 | AC | 1 ms
6,940 KB |
testcase_18 | AC | 1 ms
6,940 KB |
testcase_19 | AC | 1 ms
6,944 KB |
ソースコード
#![allow(unused_mut, non_snake_case, unused_macros, unused_imports)] use std::cmp::{max, min, Ordering}; use std::mem::{swap}; use std::collections::{HashMap, HashSet, BinaryHeap, VecDeque}; use std::iter::FromIterator; // 高速 EOF要 //macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();input_inner!{iter, $($r)*}};($($r:tt)*) => {let mut s = {use std::io::Read;let mut s = String::new();std::io::stdin().read_to_string(&mut s).unwrap();s};let mut iter = s.split_whitespace();input_inner!{iter, $($r)*}};} //macro_rules! input_inner {($iter:expr) => {};($iter:expr, ) => {};($iter:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($iter, $t);input_inner!{$iter $($r)*}};} //macro_rules! read_value {($iter:expr, ( $($t:tt),* )) => {( $(read_value!($iter, $t)),* )};($iter:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()};($iter:expr, chars) => {read_value!($iter, String).chars().collect::<Vec<char>>()};($iter:expr, usize1) => {read_value!($iter, usize) - 1};($iter:expr, $t:ty) => {$iter.next().unwrap().parse::<$t>().expect("Parse error")};} // 低速 EOF不要 macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};} macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};} macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, chars) => {read_value!($next, String).chars().collect::<Vec<char>>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};} /* <url:https://yukicoder.me/problems/no/228> 問題文============================================================ ================================================================= 解説============================================================= ================================================================ */ fn main() { input! {a:[[i32;4];4]} let mut a:Vec<Vec<i32>> = a; let dir:Vec<i32> = vec![1, 0, -1, 0]; loop { let mut update = false; 'check: for i in 0..4{ for j in 0..4{ if a[i as usize][j as usize] != 0 { continue; } let now = i*4 + j + 1; for k in 0..4 as usize{ let ny:i32= i + dir[k]; let nx:i32 = j + dir[k^1]; if ny < 0 || ny >= 4||nx < 0||nx >= 4{ continue; } if a[ny as usize][nx as usize] == now{ update = true; let t = a[i as usize][j as usize].clone(); a[i as usize][j as usize] = a[ny as usize][nx as usize].clone(); a[ny as usize][nx as usize] = t; break 'check; } } break 'check; } } if update { continue; } break; } let mut ok = true; for i in 0..4{ for j in 0..4{ if a[i as usize][j as usize] as usize == (i*4+j+1){ continue; } if i == 3 && j == 3{ continue; } ok = false; } } println!("{}", if ok {"Yes"} else {"No"}); }