結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 2 ms
6,676 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 2 ms
6,676 KB
testcase_12 WA -
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 1 ms
6,676 KB
testcase_15 AC 100 ms
63,232 KB
testcase_16 TLE -
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 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 80 ms
12,672 KB
testcase_24 AC 8 ms
6,676 KB
testcase_25 AC 12 ms
6,676 KB
testcase_26 AC 329 ms
19,792 KB
testcase_27 WA -
testcase_28 AC 101 ms
28,476 KB
testcase_29 AC 104 ms
52,224 KB
testcase_30 AC 210 ms
46,100 KB
testcase_31 AC 331 ms
35,996 KB
testcase_32 AC 400 ms
56,940 KB
testcase_33 TLE -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 1,422 ms
67,808 KB
testcase_37 TLE -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
権限があれば一括ダウンロードができます

ソースコード

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