結果

問題 No.1434 Make Maze
ユーザー ktr216ktr216
提出日時 2021-03-19 23:13:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 2,102 bytes
コンパイル時間 1,941 ms
コンパイル使用メモリ 172,176 KB
実行使用メモリ 5,500 KB
最終ジャッジ日時 2023-08-16 09:26:44
合計ジャッジ時間 7,192 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

typedef long long ll;

vector<string> solve(int H, int W, int X) {
    int minX = H + W - 2;
    if (X < minX) return {"-1"};
    int A = X - minX;
    if (A % 4) return {"-1"};
    vector<string> ret(H);
    rep(i, H) {
        if (i % 2) {
            rep(j, W - 1) ret[i].push_back('#');
            ret[i].push_back('.');
        } else {
            rep(j, W) ret[i].push_back('.');
        }
    }
    if (H % 4 == 1) {
        int maxX = (W - 1) * (H + 1) / 2 + H - 1;
        if (X > maxX) return {"-1"};
        int dx = X - minX, p = (W - 1) * 2, q = dx / p, r = dx % p;
        //cout << "dx=" << dx << " p=" << p << " q=" << q << " r=" << r << "\n"; 
        rep(i, q) {
            ret[i * 4 + 3][0] = '.';
            ret[i * 4 + 3][W - 1] = '#';
        }
        if (q * 4 + 3 < H) {
            ret[q * 4 + 3][W - 1] = '#';
            ret[q * 4 + 3][W - 1 - r / 2] = '.';
        }
        return ret;
    }
    if (W % 4 == 1) {
        vector<string> r = solve(W, H, X);
        rep(i, H) rep(j, W) ret[i][j] = r[j][i];
        return ret;
    }
    int maxX = (W - 1) * (H - 1) / 2 + H - 1 + W / 4 * 4;
    //cout << "maxX=" << maxX << "\n";
    if (X > maxX) return {"-1"};
    int dx = X - minX, p = (W - 1) * 2, q = dx / p, r = dx % p;
    //cout << "dx=" << dx << " p=" << p << " q=" << q << " r=" << r << "\n"; 
    if (q > H / 4) {
        r += (q - H / 4) * p;
        q = H / 4;
    }
    rep(i, q) {
        ret[i * 4 + 3][0] = '.';
        ret[i * 4 + 3][W - 1] = '#';
    }
    if (r > 0 && q * 4 + 3 < H && W - 1 - r / 2 >= 0) {
        ret[q * 4 + 3][W - 1] = '#';
        ret[q * 4 + 3][W - 1 - r / 2] = '.';
        return ret;
    }
    rep(i, r / 4) {
        ret[H - 2][i * 4] = '.';
        ret[H - 3][i * 4 + 1] = '#';
        ret[H - 2][i * 4 + 2] = '.';
        ret[H - 1][i * 4 + 3] = '#';
    }
    return ret;
}

int main() {
    int H, W, X;
    cin >> H >> W >> X;
    vector<string> ans = solve(H, W, X);
    rep(i, ans.size()) cout << ans[i] << "\n";
}
0