結果

問題 No.1434 Make Maze
ユーザー tonyu0
提出日時 2021-03-19 23:34:18
言語 Rust
(1.83.0 + proconio)
結果
WA  
実行時間 -
コード長 1,942 bytes
コンパイル時間 13,582 ms
コンパイル使用メモリ 382,208 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-19 02:14:02
合計ジャッジ時間 16,793 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 7 WA * 23
権限があれば一括ダウンロードができます

ソースコード

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 h: usize = itr.next().unwrap().parse().unwrap();
    let mut w: usize = itr.next().unwrap().parse().unwrap();
    let x: usize = itr.next().unwrap().parse().unwrap();

    let mn = h + w - 2;
    let mut reversed = false;
    if !((h + 1) / 2 % 2 == 1 || ((h + 1) / 2 % 2 == 0 && (w + 1) / 2 % 2 == 0)) {
        std::mem::swap(&mut h, &mut w);
        reversed = true;
    }
    let mx = (h + 1) / 2 * (w - 1) + h - 1;
    // println!("{} {}", mn, mx);
    if mn <= x && x <= mx && (mx - x) % 4 == 0 {
        let mut g = vec![vec!['.'; w]; h];
        for i in 0..h {
            if i % 2 == 1 {
                for j in 0..w {
                    g[i][j] = '#';
                }
            }
        }
        let mut dec = (mx - x) / 4;
        for i in 0..h {
            if (i + 1) % 4 == 0 {
                let dec_max = w / 2;
                if dec_max <= dec {
                    g[i][w - 1] = '.';
                    dec -= dec_max;
                } else {
                    g[i][dec * 2] = '.';
                }
            } else if (i + 1) % 2 == 0 {
                g[i][w - 1] = '.';
            }
        }
        if !reversed {
            for i in 0..h {
                for j in 0..w {
                    print!("{}", g[i][j]);
                }
                println!("");
            }
        } else {
            let mut rg = vec![vec!['.'; h]; w];
            for i in 0..h {
                for j in 0..w {
                    rg[j][i] = g[i][j];
                }
            }
            for i in 0..w {
                for j in 0..h {
                    print!("{}", rg[i][j]);
                }
                println!("");
            }
            println!("");
        }
    } else {
        println!("-1");
    }
}
0