結果

問題 No.2641 draw X
ユーザー nono00nono00
提出日時 2024-02-19 23:19:37
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,143 bytes
コンパイル時間 3,642 ms
コンパイル使用メモリ 275,500 KB
実行使用メモリ 152,104 KB
最終ジャッジ日時 2024-02-19 23:19:56
合計ジャッジ時間 14,793 ms
ジャッジサーバーID
(参考情報)
judge14 / judge16
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 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 WA -
testcase_09 AC 1 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 1 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 99 ms
63,232 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 2 ms
6,676 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 49 ms
10,460 KB
testcase_21 AC 58 ms
15,088 KB
testcase_22 AC 78 ms
13,092 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 9 ms
6,676 KB
testcase_26 WA -
testcase_27 AC 49 ms
8,456 KB
testcase_28 AC 74 ms
28,476 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 160 ms
35,996 KB
testcase_32 WA -
testcase_33 AC 1,475 ms
135,812 KB
testcase_34 AC 579 ms
76,092 KB
testcase_35 AC 629 ms
71,140 KB
testcase_36 WA -
testcase_37 TLE -
testcase_38 AC 552 ms
71,540 KB
testcase_39 WA -
testcase_40 TLE -
testcase_41 WA -
testcase_42 AC 753 ms
84,428 KB
testcase_43 WA -
権限があれば一括ダウンロードができます

ソースコード

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];
                    que.emplace(a[i][j], i, j, k);
                }
            }
        }
    }
    while (!que.empty()) {
        auto [d, i, j, k] = que.top();
        que.pop();
        if (ans[i][j][k] > d) continue;
        int ni = i + DI[k];
        int nj = j + DJ[k];
        if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
        if (ans[ni][nj][k] < d - 1) {
            ans[ni][nj][k] = d - 1;
            que.emplace(ans[ni][nj][k], ni, nj, k);
        }
    }
    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