結果
| 問題 |
No.228 ゆきこちゃんの 15 パズル
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-04-27 23:34:29 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,515 bytes |
| コンパイル時間 | 18,160 ms |
| コンパイル使用メモリ | 378,896 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-22 14:57:23 |
| 合計ジャッジ時間 | 15,144 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 11 WA * 6 |
ソースコード
use std::io::*;
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 mut table = vec![vec![0i32; 4]; 4];
let mut cx = 0i32;
let mut cy = 0i32;
for i in 0..4 {
for j in 0..4 {
table[i][j] = itr.next().unwrap().parse().unwrap();
if table[i][j] == 0 {
cx = j as i32;
cy = i as i32;
}
}
}
let dx: Vec<i32> = [0, -1, 0, 1].to_vec();
let dy: Vec<i32> = [1, 0, -1, 0].to_vec();
loop {
let target = cy * 4 + cx + 1;
let mut moved = false;
let mut tigau = 0;
for i in 0..4 {
let nx = cx + dx[i];
let ny = cy + dy[i];
if 0 <= nx && nx < 4 && 0 <= ny && ny < 4 {
if table[ny as usize][nx as usize] != ny * 4 + nx + 1 {
tigau += 1;
}
if table[ny as usize][nx as usize] == target {
moved = true;
table[cy as usize][cx as usize] = table[ny as usize][nx as usize];
table[ny as usize][nx as usize] = 0;
cx = nx;
cy = ny;
break;
}
}
}
if !moved {
if tigau > 0 {
println!("No",);
} else {
println!("Yes",);
}
return;
}
}
}