結果

問題 No.1434 Make Maze
ユーザー StrorkisStrorkis
提出日時 2021-03-20 20:27:20
言語 Rust
(1.77.0)
結果
AC  
実行時間 75 ms / 2,000 ms
コード長 2,320 bytes
コンパイル時間 1,007 ms
コンパイル使用メモリ 145,604 KB
実行使用メモリ 5,844 KB
最終ジャッジ日時 2023-08-16 09:36:43
合計ジャッジ時間 6,859 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 74 ms
5,828 KB
testcase_03 AC 75 ms
5,844 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 1 ms
4,384 KB
testcase_12 AC 4 ms
4,384 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 4 ms
4,380 KB
testcase_15 AC 20 ms
4,384 KB
testcase_16 AC 6 ms
4,380 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 9 ms
4,380 KB
testcase_19 AC 38 ms
4,384 KB
testcase_20 AC 1 ms
4,384 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1 ms
4,384 KB
testcase_24 AC 26 ms
4,380 KB
testcase_25 AC 46 ms
4,564 KB
testcase_26 AC 5 ms
4,380 KB
testcase_27 AC 25 ms
4,380 KB
testcase_28 AC 5 ms
4,380 KB
testcase_29 AC 1 ms
4,384 KB
testcase_30 AC 9 ms
4,380 KB
testcase_31 AC 9 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#[allow(dead_code)]
mod io {
    use std::str::{FromStr, SplitWhitespace};

    pub struct Scanner<'a>(pub SplitWhitespace<'a>);

    impl<'a> Scanner<'a> {
        pub fn next<T: FromStr>(&mut self) -> T {
            self.0.next().unwrap().parse().ok().unwrap()
        }
    }

    pub fn vec<T, F: FnMut() -> T>(f: F, n: usize) -> Vec<T> {
        std::iter::repeat_with(f).take(n).collect()
    }
}

use std::io::Read;

fn main() {
    let ref mut buf = String::new();
    std::io::stdin().read_to_string(buf).ok();
    let mut sc = io::Scanner(buf.split_whitespace());

    let (h, w, x) = {
        (sc.next::<usize>(), sc.next::<usize>(), sc.next::<usize>())
    };
    let (is_swapped, h, w) = {
        if h % 4 == 3 { (true, w, h) } else { (false, h, w) }
    };
    
    if x < (h - 1) + (w - 1) {
        return println!("-1");
    }
    let mut x = x - ((h - 1) + (w - 1));

    let mut cell = vec![vec!['.'; w]; h];
    for i in (1..h).step_by(2) {
        for j in (1..w).step_by(2) {
            cell[i][j] = '#';
        }
    }

    if h % 4 == 3 {
        for j in (1..w).step_by(2) {
            if x >= 4 {
                if j % 4 == 1 {
                    cell[0][j] = '#';
                } else {
                    cell[2][j] = '#';
                    x -= 4;
                }    
            } else {
                cell[0][j] = '#';
            }
        }
    }

    for i in (h % 4..h).step_by(2) {
        if i % 4 == 4 - h % 4 {
            let mut done = false;
            for j in (0..w).rev().step_by(2) {
                if done {
                    cell[i][j] = '#';
                } else if j > 0 && x >= 4 {
                    cell[i][j] = '#';
                    x -= 4;
                } else {
                    done = true;
                }
            }
        } else {
            for j in (0..w - 1).step_by(2) {
                cell[i][j] = '#';
            }    
        }
    }

    if x > 0 {
        return println!("-1");
    }

    if is_swapped {
        for i in 0..w {
            for j in 0..h {
                print!("{}", cell[j][i]);
            }
            println!();
        }
    } else {
        for i in 0..h {
            for j in 0..w {
                print!("{}", cell[i][j]);
            }
            println!();
        }
    }
}
0