結果

問題 No.228 ゆきこちゃんの 15 パズル
ユーザー tonyu0tonyu0
提出日時 2020-04-27 23:34:29
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,515 bytes
コンパイル時間 4,083 ms
コンパイル使用メモリ 135,204 KB
実行使用メモリ 5,008 KB
最終ジャッジ日時 2023-08-14 16:23:09
合計ジャッジ時間 2,680 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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;
        }
    }
}
0