結果

問題 No.1434 Make Maze
ユーザー se1ka2se1ka2
提出日時 2021-03-19 22:19:06
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 16 ms / 2,000 ms
コード長 1,663 bytes
コンパイル時間 667 ms
コンパイル使用メモリ 66,820 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-08-16 09:23:27
合計ジャッジ時間 7,012 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
using namespace std;

bool ans[1005][1005];

int main()
{
    int h, w, x;
    cin >> h >> w >> x;
    if(x < h + w - 2 || (x - (h + w - 2)) % 4){
        cout << -1 << endl;
        return 0;
    }
    bool f = false;
    if(h % 4 == 3){
        f = true;
        swap(h, w);
    }
    for(int i = 1; i < h / 4 * 4; i += 2){
        if(i % 4 == 1){
            for(int j = 0; j < w - 1; j++) ans[i][j] = true;
        }
        else{
            for(int j = 1; j < w; j++) ans[i][j] = true;
        }
    }
    if(h % 4 == 3){
        for(int j = 1; j < w; j += 2){
            if(j % 4 == 1){
                ans[h - 1][j] = ans[h - 2][j] = true;
            }
            else{
                ans[h - 2][j] = ans[h - 3][j] = true;
            }
        }
    }
    int y = h * w - (h / 2) * (w - 1) - 1;
    if(h % 4 == 3){
        y -= 2;
        for(int j = 3; j < w; j += 4){
            if(y <= x) break;
            ans[h - 1][j] = true;
            ans[h - 3][j] = false;
            y -= 4;
        }
    }
    for(int i = 1; i < h; i += 4){
        for(int j = w - 3; j >= 0; j -= 2){
            if(y <= x) break;
            ans[i][j + 2] = true;
            ans[i][j] = false;
            y -= 4;
        }
    }
    if(y != x){
        cout << -1 << endl;
        return 0;
    }
    if(f){
        swap(h, w);
        for(int i = 0; i < max(h, w); i++){
            for(int j = i + 1; j < max(h, w); j++) swap(ans[i][j], ans[j][i]);
        }
    }
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(ans[i][j]) cout << '#';
            else cout << '.';
        }
        cout << endl;
    }
}
0