結果
| 問題 | No.13 囲みたい! | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2019-12-20 16:17:53 | 
| 言語 | Rust (1.83.0 + proconio) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 2 ms / 5,000 ms | 
| コード長 | 1,820 bytes | 
| コンパイル時間 | 11,577 ms | 
| コンパイル使用メモリ | 402,924 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-07-08 11:42:33 | 
| 合計ジャッジ時間 | 12,565 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 16 | 
ソースコード
use std::io::Read;
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 w: usize = itr.next().unwrap().parse().unwrap();
    let h: usize = itr.next().unwrap().parse().unwrap();
    let m: Vec<Vec<u32>> = (0..h)
        .map(|_| {
            (0..w)
                .map(|_| itr.next().unwrap().parse().unwrap())
                .collect()
        })
        .collect();
    let mut checked: Vec<Vec<bool>> = vec![vec![false; w]; h];
    let mut q = std::collections::VecDeque::new();
    let dx: Vec<isize> = [0, 1, 0, -1].to_vec();
    let dy: Vec<isize> = [1, 0, -1, 0].to_vec();
    for i in 0..h {
        for j in 0..w {
            let checking_num = m[i][j];
            if checked[i][j] {
                continue;
            }
            q.push_back((i, j, 0, 0));
            while let Some((y, x, py, px)) = q.pop_front() {
                checked[y][x] = true;
                for k in 0..4 {
                    let nx = x as isize + dx[k];
                    let ny = y as isize + dy[k];
                    if nx == px && ny == py {
                        continue;
                    }
                    if 0 <= nx
                        && nx < w as isize
                        && 0 <= ny
                        && ny < h as isize
                        && m[ny as usize][nx as usize] == checking_num
                    {
                        if checked[ny as usize][nx as usize] {
                            println!("possible");
                            return;
                        }
                        q.push_back((ny as usize, nx as usize, y as isize, x as isize));
                    }
                }
            }
        }
    }
    println!("impossible");
}
            
            
            
        