結果

問題 No.1434 Make Maze
ユーザー trineutrontrineutron
提出日時 2021-03-19 23:26:49
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 3,084 bytes
コンパイル時間 2,448 ms
コンパイル使用メモリ 202,252 KB
実行使用メモリ 5,532 KB
最終ジャッジ日時 2023-08-16 09:28:25
合計ジャッジ時間 8,114 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int h, w, x;
    cin >> h >> w >> x;
    int hhalf = h / 2, whalf = w / 2, rest = x / 2 - hhalf - whalf, longest = (hhalf + 1) * (whalf + 1) - 1;
    if (x % 2 or x / 2 % 2 != (hhalf + whalf) % 2 or rest < 0 or longest < x / 2)
    {
        cout << -1 << endl;
        return 0;
    }
    vector<string> ans(h);
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            ans.at(i).push_back('.');
            if (i % 2 and j % 2)
            {
                ans.at(i).at(j) = '#';
            }
        }
    }
    if (hhalf % 2 == 0)
    {
        int prevhole = 0;
        for (int i = 1; i < h; i += 2)
        {
            int hole = 2 * whalf;
            if (rest >= prevhole and prevhole)
            {
                hole = 0;
                rest -= prevhole;
            }
            else if (rest and prevhole)
            {
                hole = prevhole - rest;
                rest = 0;
            }
            prevhole = hole;
            for (int j = 0; j < w; j += 2)
            {
                if (j != hole)
                {
                    ans.at(i).at(j) = '#';
                }
            }
        }
    }
    else if (whalf % 2 == 0)
    {
        int prevhole = 0;
        for (int i = 1; i < w; i += 2)
        {
            int hole = 2 * hhalf;
            if (rest >= prevhole and prevhole)
            {
                hole = 0;
                rest -= prevhole;
            }
            else if (rest and prevhole)
            {
                hole = prevhole - rest;
                rest = 0;
            }
            prevhole = hole;
            for (int j = 0; j < h; j += 2)
            {
                if (j != hole)
                {
                    ans.at(j).at(i) = '#';
                }
            }
        }
    }
    else
    {
        int prevhole = 0;
        for (int i = 1; i < h; i += 2)
        {
            int hole = 2 * whalf;
            if (i >= h - 2 and rest)
            {
                break;
            }
            if (rest >= prevhole and prevhole)
            {
                hole = 0;
                rest -= prevhole;
            }
            else if (rest and prevhole)
            {
                hole = prevhole - rest;
                rest = 0;
            }
            prevhole = hole;
            for (int j = 0; j < w; j += 2)
            {
                if (j != hole)
                {
                    ans.at(i).at(j) = '#';
                }
            }
        }
        if (rest)
        {
            prevhole = h - 3;
            for (int i = 1; i < w; i += 2)
            {
                int hole = h - 3;
                if (rest and prevhole == h - 3)
                {
                    hole = h - 1;
                    rest -= 2;
                }
                prevhole = hole;
                ans.at(2 * h - 4 - hole).at(i) = '#';
            }
        }
    }
    for (auto &&s : ans)
    {
        cout << s << '\n';
    }
    return 0;
}
0