結果

問題 No.1434 Make Maze
ユーザー merom686
提出日時 2021-03-19 22:57:41
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,785 bytes
コンパイル時間 1,113 ms
コンパイル使用メモリ 91,704 KB
最終ジャッジ日時 2025-01-19 19:16:12
ジャッジサーバーID
(参考情報)
judge5 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 1
other AC * 9 WA * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

char c[1000][1000];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int h, w, x;
    cin >> h >> w >> x;

    h = (h + 1) / 2;
    w = (w + 1) / 2;

    if (x % 2 != 0) {
        cout << -1 << endl;
        exit(0);
    }
    x /= 2;

    int x0 = (h - 1) + (w - 1), x1 = h * w - 1;
    if ((x1 - x0) % 2 != 0) x1--;

    if (!(x0 <= x && x <= x1 && (x - x0) % 2 == 0)) {
        cout << -1 << endl;
        exit(0);
    }
    x -= x0;
    x /= 2;

    for (int i = 0; i < h * 2 - 1; i++) {
        for (int j = 0; j < w * 2 - 1; j++) {
            c[i][j] = '#';
        }
    }
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            c[i * 2][j * 2] = '.';
        }
    }
    for (int j = 0; j < w - 1; j++) {
        c[0][j * 2 + 1] = '.';
    }
    for (int i = 0; i < h - 1; i++) {
        c[i * 2 + 1][(w - 1) * 2] = '.';
    }
    for (int i = h - 2; i > 0; i -= 2) {
        if (x == 0) break;
        for (int j = w - 2; j >= 0; j--) {
            c[i * 2 + 0][j * 2 + 1] = '.';
            c[i * 2 + 2][j * 2 + 1] = '.';
            x--;
            if (j == 0 || x == 0) {
                c[i * 2 + 1][(w - 1) * 2] = '#';
                c[i * 2 + 1][j * 2] = '.';
                break;
            }
        }
    }
    for (int j = w - 3; j >= 0; j -= 2) {
        if (x == 0) break;
        c[1][j * 2 + 0] = '.';
        c[1][j * 2 + 2] = '.';
        c[0][j * 2 + 1] = '#';
        c[2][j * 2 + 1] = '.';
        x--;
    }

    for (int i = 0; i < h * 2 - 1; i++) {
        c[i][w * 2] = 0;
        cout << c[i] << '\n';
    }

    return 0;
}
0