結果

問題 No.1434 Make Maze
ユーザー fukafukatani
提出日時 2021-03-19 22:59:59
言語 Rust
(1.83.0 + proconio)
結果
WA  
実行時間 -
コード長 2,655 bytes
コンパイル時間 14,811 ms
コンパイル使用メモリ 390,568 KB
実行使用メモリ 9,856 KB
最終ジャッジ日時 2024-11-19 00:34:04
合計ジャッジ時間 18,173 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 1
other AC * 11 WA * 19
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: variable `reduced` is assigned to, but never used
  --> src/main.rs:28:13
   |
28 |     let mut reduced = false;
   |             ^^^^^^^
   |
   = note: consider using `_reduced` instead
   = note: `#[warn(unused_variables)]` on by default

warning: value assigned to `reduced` is never read
  --> src/main.rs:30:9
   |
30 |         reduced = true;
   |         ^^^^^^^
   |
   = help: maybe it is overwritten before being read?
   = note: `#[warn(unused_assignments)]` on by default

ソースコード

diff #

#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;
use std::ops::Bound::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (mut h, mut w, x) = (v[0], v[1], v[2]);
    let mut swapped = false;
    if (w - 3) % 4 == 0 && (h - 3) % 4 != 0 {
        swapped = true;
        std::mem::swap(&mut h, &mut w);
    }

    let mut max_len = (h - 1) * (w + 1) / 2 + (w - 1);
    let mut reduced = false;
    if (w - 3) % 4 == 0 {
        reduced = true;
        max_len -= 2;
    }
    let min_len = h + w - 2;
    if x < min_len || x > max_len {
        println!("-1");
        return;
    }
    if (x - min_len) % 4 != 0 {
        println!("-1");
        return;
    }
    debug!(min_len, max_len);

    let mut used = vec![];
    for x in 0..w {
        if x % 2 == 0 {
            continue;
        }
        if x % 4 == 1 {
            for y in 0..h - 1 {
                if y % 2 == 0 {
                    used.push((x, y));
                }
            }
        } else {
            for y in (1..h).rev() {
                if y % 2 == 0 {
                    used.push((x, y));
                }
            }
        }
    }
    debug!(used);
    used.reverse();

    let mut added = vec![];
    let mut cur = max_len;
    while cur > max_len {
        let (x, y) = used.pop().unwrap();
        if x % 4 == 1 {
            added.push((x, y + 2));
        } else {
            added.push((x, y - 2));
        }
        cur -= 4;
    }
    used.append(&mut added);

    let mut grid = vec![vec!['.'; w]; h];
    for (x, y) in used {
        grid[y][x] = '#';
    }
    for y in 0..h {
        for x in 0..w {
            if x % 2 == 1 && y % 2 == 1 {
                grid[y][x] = '#';
            }
        }
    }
    if swapped {
        for x in 0..w {
            for y in 0..h {
                print!("{}", grid[y][x]);
            }
            println!("");
        }
    } else {
        for y in 0..h {
            for x in 0..w {
                print!("{}", grid[y][x]);
            }
            println!("");
        }
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
0