結果

問題 No.13 囲みたい!
ユーザー drymousedrymouse
提出日時 2024-02-17 11:31:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 3,259 bytes
コンパイル時間 3,112 ms
コンパイル使用メモリ 73,276 KB
実行使用メモリ 10,132 KB
最終ジャッジ日時 2024-02-17 11:32:07
合計ジャッジ時間 8,117 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 20 ms
6,676 KB
testcase_04 AC 4 ms
6,676 KB
testcase_05 AC 217 ms
6,676 KB
testcase_06 AC 5 ms
6,676 KB
testcase_07 TLE -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;

int main(void) {
    int W, H;
    cin >> W >> H;
    int M[H + 2][W + 2];
    int maxM = 0;
    for (int i = 0; i < H + 2; i++) {
        for (int j = 0; j < W + 2; j++) {
            if (i*j == 0 || (i-H-1)*(j-W-1) == 0) {
                M[i][j] = 0;
            } else {
                cin >> M[i][j];
                maxM = max(maxM, M[i][j]);
            }
        }
    }

    //-1: なし 0: 未探索 >1: 探索済
    for (int k = 1; k < maxM + 1; k++) {
        int numver = 0; // the number of vertices
        int vertices[H + 2][W + 2];
        for (int i = 0; i < H + 2; i++) {
            for (int j = 0; j < W + 2; j++) {
                if (M[i][j] == k) {
                    numver++;
                    vertices[i][j] = 0;
                } else {
                    vertices[i][j] = -1;
                }
            }
        }
        int step = 1;
        for (int i = 1; i < H + 1; i++) {
            for (int j = 1; j < W + 1; j++) {
                if (vertices[i][j] == 0) {
                    vertices[i][j] = step;
                    for (int l = 0; l < numver; l++) {
                        for (int i2 = 1; i2 < H + 1; i2++) {
                            for (int j2 = 1; j2 < W + 1; j2++) {
                                if (vertices[i2][j2] == step) {
                                    int counter = 0;
                                    int* tar = &vertices[i2][j2-1];
                                    if (*tar == 0) {
                                        *tar = step + 1;
                                    } else if (*tar > 0 && *tar <= step) {
                                        counter++;
                                    }
                                    tar = &vertices[i2][j2+1];
                                    if (*tar == 0) {
                                        *tar = step + 1;
                                    } else if (*tar > 0 && *tar <= step) {
                                        counter++;
                                    }
                                    tar = &vertices[i2-1][j2];
                                    if (*tar == 0) {
                                        *tar = step + 1;
                                    } else if (*tar > 0 && *tar <= step) {
                                        counter++;
                                    }
                                    tar = &vertices[i2+1][j2];
                                    if (*tar == 0) {
                                        *tar = step + 1;
                                    } else if (*tar > 0 && *tar <= step) {
                                        counter++;
                                    }
                                    if (counter > 1) {
                                        cout << "possible" << endl;
                                        return 0;
                                    }
                                }
                            }
                        }
                        step++;
                    }
                } else {
                    
                }
            }
        }
    }
    cout << "impossible" << endl;
    return 0;
}
0