結果

問題 No.1434 Make Maze
ユーザー norikamenorikame
提出日時 2021-03-20 10:57:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 4,173 bytes
コンパイル時間 2,438 ms
コンパイル使用メモリ 208,252 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-30 21:50:53
合計ジャッジ時間 6,385 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

using ll = long long;
using ull = unsigned long long;
#define v(t) vector<t>
#define p(t) pair<t, t>
#define p2(t, s) pair<t, s>
#define vp(t) v(p(t))

#define rep(i, n) for (int i=0,i##_len=((int)(n)); i<i##_len; ++i)
#define rep2(i, a, n) for (int i=((int)(a)),i##_len=((int)(n)); i<=i##_len; ++i)
#define repr(i, n) for (int i=((int)(n)-1); i>=0; --i)
#define rep2r(i, a, n) for (int i=((int)(n)),i##_len=((int)(a)); i>=i##_len; --i)

#define repi(itr, c) for (__typeof((c).begin()) itr=(c).begin(); itr!=(c).end(); ++itr)
#define repir(itr, c) for (__typeof((c).rbegin()) itr=(c).rbegin(); itr!=(c).rend(); ++itr)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define eb emplace_back

#define INF (1e9)
#define LINF (1e18)
#define PI (acos(-1))
#define EPS (1e-7)
#define DEPS (1e-10)

// 終了後、自主研究、WA

int main(){
    int h, w, x;
    cin >> h >> w >> x;
    if (x%2 != 0) {
        cout << -1 << endl;
        return 0;
    }
    if (x < h+w-2) {
        cout << -1 << endl;
        return 0;
    }
    int h2 = (h+1)/2, w2 = (w+1)/2, x2 = x / 2, mxval = (h2*w2-1);
    if (h2%2==0 && w2%2==0 && x2>(h2-1)*(w2-1)+(w2-2)) {
        if (x2 > mxval-1) {
            cout << -1 << endl;
            return 0;
        }
        int add = x2 - (h2+w2-2), add2 = (add - (w2-2) * (h2-1));
        if (add2%2 != 0) {
            cout << -1 << endl;
            return 0;
        }
        add2 /= 2;
        v(string) ans(h, string(w, '.'));
        rep(i, h) rep(j, w) if (i%2!=0&&j%2!=0) ans[i][j] = '#';
        int len1 = (w2-2) / 2;
        for (int i=0; i<h-1; i+=2) ans[i][1] = '#';
        for (int i=0; i<len1; ++i) {
            int i2 = 2 + 4*i;
            for (int j=h-1; j>=1; j-=2) ans[j][i2+1] = '#';
            if (i+1<len1) for (int j=0; j<h-1; j+=2) ans[j][i2+3] = '#';
        }
        if (add2 > 0) {
            for (int i=0; i<add2; ++i) {
                int i2 = i*4;
                ans[i2+1][w-3] = '#';
                ans[i2+3][w-1] = '#';
            }
            for (int i=add2*4; i+1<=h-1; i+=2) ans[i+1][w-3] = '#';
        }
        rep(i, h) cout << ans[i] << endl;
    }
    else {
        if (x2 > mxval) {
            cout << -1 << endl;
            return 0;
        }
        bool r = false;
        if (h2%2!=0 && w2%2!=0) r = (h2>=w2);
        else if (h2%2==0 && w2%2==0) r = true;
        else r = (w2%2 != 0); // r==true : 上下方向にジグザグする、そうじゃなかったら縦横を後で交換
        int add = x2 - (h2+w2-2);
        if (add%2 != 0) {
            cout << -1 << endl;
            return 0;
        }
        if (!r) {
            swap(h2, w2);
            swap(h, w);
        }
        v(string) ans(h, string(w, '.'));
        rep(i, h) rep(j, w) if (i%2!=0&&j%2!=0) ans[i][j] = '#';
        int len1 = add / ((h2-1)*2), len2 = add % ((h2-1)*2);
        if (len2%2 != 0) {
            cout << -1 << endl;
            return 0;
        }
        len2 /= 2;
        for (int i=0; i<h-1; i+=2) ans[i][1] = '#';
        for (int i=0; i<len1; ++i) {
            int i2 = 2 + 4*i;
            for (int j=h-1; j>=1; j-=2) ans[j][i2+1] = '#';
            for (int j=0; j<h-1; j+=2) ans[j][i2+3] = '#';
        }
        int i3 = 2 + 4*len1;
        if (len2 > 0) {
            for (int i=h-1; i>=0; i-=2) if (i!=(h-1)-2*len2) ans[i][i3+1] = '#';
            if (i3+3 < w) for (int i=0; i<=h-1; i+=2) ans[i][i3+3] = '#';
            i3 += 4;
        }
        for (int j=i3; j<w; j+=2) {
            if (j+1 < w) for (int i=h-3; i>=0; i-=2) ans[i][j+1] = '#';
        }
        if (r) rep(i, h) cout << ans[i] << endl;
        else {
            rep(i, w) {
                string tmp;
                rep(j, h) tmp += ans[j][i];
                cout << tmp << endl;
            }
        }
    }
    return 0;
}
0