結果

問題 No.2641 draw X
ユーザー chineristACchineristAC
提出日時 2024-02-19 23:13:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 4,074 bytes
コンパイル時間 851 ms
コンパイル使用メモリ 84,280 KB
実行使用メモリ 13,480 KB
最終ジャッジ日時 2024-02-19 23:13:33
合計ジャッジ時間 5,396 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,480 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 67 ms
13,312 KB
testcase_16 AC 85 ms
13,312 KB
testcase_17 AC 2 ms
6,676 KB
testcase_18 AC 2 ms
6,676 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 7 ms
6,676 KB
testcase_21 AC 14 ms
6,676 KB
testcase_22 AC 6 ms
6,676 KB
testcase_23 AC 11 ms
6,676 KB
testcase_24 AC 5 ms
6,676 KB
testcase_25 AC 5 ms
6,676 KB
testcase_26 AC 15 ms
6,676 KB
testcase_27 AC 4 ms
6,676 KB
testcase_28 TLE -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>

int main() {
    int H, W;
    std::cin >> H >> W;

    std::vector<std::string> S(H);
    for (int i = 0; i < H; ++i) {
        std::cin >> S[i];
    }

    std::vector<std::vector<int>> maximum_r(H, std::vector<int>(W, H + W));
    

    for (int s = -(W - 1); s < H; ++s) {
        int tmp = 0;
        for (int j = 0; j < W; ++j) {
            int i = s + j;
            if (!(0 <= i && i < H)) {
                continue;
            }

            if (S[i][j] == '#') {
                maximum_r[i][j] = std::min(maximum_r[i][j], tmp);
                ++tmp;
            } else {
                maximum_r[i][j] = -1;
                tmp = 0;
            }
        }

        tmp = 0;
        for (int j = W - 1; j >= 0; --j) {
            int i = s + j;
            if (!(0 <= i && i < H)) {
                continue;
            }

            if (S[i][j] == '#') {
                maximum_r[i][j] = std::min(maximum_r[i][j], tmp);
                ++tmp;
            } else {
                maximum_r[i][j] = -1;
                tmp = 0;
            }
        }
    }
    

    for (int t = 0; t < H + W - 1; ++t) {
        int tmp = 0;
        for (int j = W - 1; j >= 0; --j) {
            int i = t - j;
            if (!(0 <= i && i < H)) {
                continue;
            }

            if (S[i][j] == '#') {
                maximum_r[i][j] = std::min(maximum_r[i][j], tmp);
                ++tmp;
            } else {
                maximum_r[i][j] = 0;
                tmp = 0;
            }
        }

        tmp = 0;
        for (int j = 0; j < W; ++j) {
            int i = t - j;
            if (!(0 <= i && i < H)) {
                continue;
            }

            if (S[i][j] == '#') {
                maximum_r[i][j] = std::min(maximum_r[i][j], tmp);
                ++tmp;
            } else {
                maximum_r[i][j] = -1;
                tmp = 0;
            }
        }
    }

    std::vector<std::vector<int>> final(H, std::vector<int>(W, 0));

    for (int s = -(W - 1); s < H; ++s) {
        int tmp = -1;
        for (int j = 0; j < W; ++j) {
            int i = s + j;
            if (!(0 <= i && i < H)) {
                continue;
            }

            if (maximum_r[i][j] > 0) {
                tmp = std::max(tmp - 1, maximum_r[i][j]);
            } else {
                tmp = tmp - 1;
            }

            if (tmp >= 0) {
                final[i][j] = 1;
            }
        }

        tmp = 0;
        for (int j = W - 1; j >= 0; --j) {
            int i = s + j;
            if (!(0 <= i && i < H)) {
                continue;
            }

            if (maximum_r[i][j] > 0) {
                tmp = std::max(tmp - 1, maximum_r[i][j]);
            } else {
                tmp = tmp - 1;
            }

            if (tmp >= 0) {
                final[i][j] = 1;
            }
        }
    }

    for (int t = 0; t < H + W - 1; ++t) {
        int tmp = 0;
        for (int j = W - 1; j >= 0; --j) {
            int i = t - j;
            if (!(0 <= i && i < H)) {
                continue;
            }

            if (maximum_r[i][j] > 0) {
                tmp = std::max(tmp - 1, maximum_r[i][j]);
            } else {
                tmp = tmp - 1;
            }

            if (tmp >= 0) {
                final[i][j] = 1;
            }
        }

        tmp = 0;
        for (int j = 0; j < W; ++j) {
            int i = t - j;
            if (!(0 <= i && i < H)) {
                continue;
            }

            if (maximum_r[i][j] > 0) {
                tmp = std::max(tmp - 1, maximum_r[i][j]);
            } else {
                tmp = tmp - 1;
            }

            if (tmp >= 0) {
                final[i][j] = 1;
            }
        }
    }

    std::string ans = "Yes";
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            if (S[i][j] == '#' && !final[i][j]) {
                ans = "No";
            }
        }
    }

    std::cout << ans << std::endl;

    return 0;
}
0