結果

問題 No.2641 draw X
ユーザー nono00nono00
提出日時 2024-02-19 23:28:18
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 186 ms / 2,000 ms
コード長 3,462 bytes
コンパイル時間 3,235 ms
コンパイル使用メモリ 269,276 KB
実行使用メモリ 84,480 KB
最終ジャッジ日時 2024-02-19 23:28:26
合計ジャッジ時間 6,976 ms
ジャッジサーバーID
(参考情報)
judge16 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
6,676 KB
testcase_04 AC 1 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 1 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 116 ms
63,232 KB
testcase_16 AC 167 ms
84,480 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 12 ms
8,320 KB
testcase_21 AC 23 ms
13,952 KB
testcase_22 AC 12 ms
8,448 KB
testcase_23 AC 20 ms
12,160 KB
testcase_24 AC 8 ms
6,676 KB
testcase_25 AC 8 ms
6,676 KB
testcase_26 AC 25 ms
15,104 KB
testcase_27 AC 7 ms
6,676 KB
testcase_28 AC 52 ms
28,416 KB
testcase_29 AC 96 ms
52,224 KB
testcase_30 AC 93 ms
45,696 KB
testcase_31 AC 72 ms
34,048 KB
testcase_32 AC 123 ms
55,808 KB
testcase_33 AC 186 ms
68,992 KB
testcase_34 AC 95 ms
41,216 KB
testcase_35 AC 79 ms
36,480 KB
testcase_36 AC 129 ms
63,232 KB
testcase_37 AC 158 ms
79,360 KB
testcase_38 AC 123 ms
62,848 KB
testcase_39 AC 153 ms
71,296 KB
testcase_40 AC 161 ms
78,464 KB
testcase_41 AC 126 ms
58,752 KB
testcase_42 AC 131 ms
67,584 KB
testcase_43 AC 135 ms
65,152 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

void solve() {
    int h, w;
    std::cin >> h >> w;
    std::vector<std::string> s(h);
    for (int i = 0; i < h; i++) std::cin >> s[i];

    const int n = h + w - 1;
    std::vector<std::vector<std::pair<int, int>>> naname1(h + w - 1);
    std::vector<std::vector<std::pair<int, int>>> naname2(h + w - 1);
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (s[i][j] == '#') {
                naname1[i + j].emplace_back(i, j);
                naname2[i + w - j - 1].emplace_back(i, j);
            }
        }
    }
    const int INF = 1e9;
    std::vector a(h, std::vector<int>(w, INF));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (s[i][j] == '.') a[i][j] = 0;
        }
    }
    for (int k = 0; k < n; k++) {
        for (int l = 0; l < (int)naname1[k].size();) {
            int r = l + 1;
            while (r < (int)naname1[k].size() && naname1[k][r - 1].first + 1 == naname1[k][r].first) r++;
            int len = r - l;
            for (int c = 0; c < len; c++) {
                auto [i, j] = naname1[k][l + c];
                a[i][j] = std::min({a[i][j], c, len - c - 1});
            }
            l = r;
        }
    }
    for (int k = 0; k < n; k++) {
        for (int l = 0; l < (int)naname2[k].size();) {
            int r = l + 1;
            while (r < (int)naname2[k].size() && naname2[k][r - 1].first + 1 == naname2[k][r].first) r++;
            int len = r - l;
            for (int c = 0; c < len; c++) {
                auto [i, j] = naname2[k][l + c];
                a[i][j] = std::min({a[i][j], c, len - c - 1});
            }
            l = r;
        }
    }

    const int DI[] = {1, 1, -1, -1};
    const int DJ[] = {1, -1, 1, -1};
    std::priority_queue<std::tuple<int, int, int, int>> que;
    std::vector ans(h, std::vector(w, std::vector<int>(4)));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (a[i][j] != 0) {
                for (int k = 0; k < 4; k++) {
                    ans[i][j][k] = a[i][j] + 1;
                }
            }
        }
    }
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            for (int d = 0; d < 2; d++) {
                int ni = i + DI[d];
                int nj = j + DJ[d];
                if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
                ans[ni][nj][d] = std::max(ans[ni][nj][d], ans[i][j][d] - 1);
            }
        }
    }
    for (int i = h - 1; i >= 0; i--) {
        for (int j = 0; j < w; j++) {
            for (int d = 0; d < 2; d++) {
                int ni = i + DI[2 + d];
                int nj = j + DJ[2 + d];
                if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
                ans[ni][nj][2 + d] = std::max(ans[ni][nj][2 + d], ans[i][j][2 + d] - 1);
            }
        }
    }
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            bool ok = false;
            for (int k = 0; k < 4; k++) {
                if (ans[i][j][k] > 0) {
                    ok = true;
                }
            }
            if (s[i][j] == '#' && !ok) {
                std::cout << "No" << '\n';
                return;
            }
        }
    }
    std::cout << "Yes" << '\n';
}

int main() {
    std::cin.tie(0)->sync_with_stdio(0);
    std::cout << std::fixed << std::setprecision(16);
    int t = 1;

    while (t--) solve();
}
0