結果

問題 No.1434 Make Maze
ユーザー 鈴木ひでき鈴木ひでき
提出日時 2021-03-19 23:41:54
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 17 ms / 2,000 ms
コード長 3,766 bytes
コンパイル時間 878 ms
コンパイル使用メモリ 93,292 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-16 09:33:49
合計ジャッジ時間 6,753 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, init, end) for(ll i = init; i < end; i++)
#define REP(i, init, end) for(ll i = init; i < end + 1; i++)
#define rev(i, end, init) for(ll i = init - 1; i >= end; i--)
#define REV(i, end, init) for(ll i = init; i >= end; i--)
#define PI 3.14159265359
#define EPS 0.0000000001
// #define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


char m[1001][1001];

int main(){
    ll H, W, X;
    cin >> H >> W >> X;

    ll rowPillar, colPillar;
    rowPillar = (H - 1) / 2;
    colPillar = (W - 1) / 2;

    ll minMove, maxMove;
    minMove = W - 1 + H - 1;
    if(rowPillar % 2 == 0){
        maxMove = minMove + colPillar * (rowPillar / 2) * 4;
    }else{
        if(colPillar % 2 == 0){
            maxMove = minMove + rowPillar * (colPillar / 2) * 4;
        }else{
            maxMove = minMove + ((rowPillar - 1) * colPillar / 2 + (colPillar - 1) / 2) * 4;
        }
    }

    if(X < minMove || X > maxMove || (X - minMove) % 4 != 0){
        cout << -1 << endl;
        return 0;
    }

    rep(i, 0, H){
        rep(j, 0, W){
            if(i % 2 == 1 && j % 2 == 1){
                m[i][j] = '#';
            }else{
                m[i][j] = '.';
            }
        }
    }

    ll needDetour = (X - minMove) / 4;//cout << "need: " << needDetour << endl;
    ll rowCount, colCount;
    ll r = 0, c = 0;
    if(rowPillar % 2 == 0){
        while(r < rowPillar - 1){
            while(c < colPillar){
                if(needDetour > 0){
                    m[2 * r + 1][2 * c] = '#';
                    m[2 * r + 3][2 * c + 2] = '#';
                    needDetour--;
                }else{
                    m[2 * r][2 * c + 1] = '#';
                    m[2 * r + 2][2 * c + 1] = '#';
                }
                c++;
            }
            r += 2;
            c = 0;
        }
    }else{
        if(colPillar % 2 == 0){
            while(c < colPillar - 1){
                while(r < rowPillar){
                    if(needDetour > 0){
                        m[2 * r][2 * c + 1] = '#';
                        m[2 * r + 2][2 * c + 3] = '#';
                        needDetour--;
                    }else{
                        m[2 * r + 1][2 * c] = '#';
                        m[2 * r + 1][2 * c + 2] = '#';
                    }
                    r++;
                }
                c += 2;
                r = 0;
            }
        }else{
            while(r < rowPillar - 1){
                while(c < colPillar){
                    if(needDetour > 0){
                        m[2 * r + 1][2 * c] = '#';
                        m[2 * r + 3][2 * c + 2] = '#';
                        needDetour--;
                    }else{
                        m[2 * r][2 * c + 1] = '#';
                        m[2 * r + 2][2 * c + 1] = '#';
                    }
                    c++;
                }
                r += 2;
                c = 0;
            }
            while(c < colPillar){
                if(needDetour > 0){
                    m[2 * r][2 * c + 1] = '#';
                    m[2 * r + 2][2 * c + 3] = '#';
                    needDetour--;
                }else{
                    m[2 * r][2 * c + 1] = '#';
                    m[2 * r][2 * c + 3] = '#';
                }
                c += 2;
            }
        }
    }

    rep(i, 0, H){
        rep(j, 0, W){
            cout << m[i][j];
        }
        cout << endl;
    }

    return 0;
}
0