結果

問題 No.2641 draw X
ユーザー nono00nono00
提出日時 2024-02-19 23:22:31
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 3,151 bytes
コンパイル時間 3,383 ms
コンパイル使用メモリ 276,164 KB
実行使用メモリ 152,104 KB
最終ジャッジ日時 2024-02-19 23:22:50
合計ジャッジ時間 14,237 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 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 1 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 100 ms
63,104 KB
testcase_16 AC 1,566 ms
150,580 KB
testcase_17 AC 2 ms
6,676 KB
testcase_18 AC 1 ms
6,676 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 48 ms
10,460 KB
testcase_21 AC 60 ms
15,088 KB
testcase_22 AC 73 ms
13,092 KB
testcase_23 AC 35 ms
12,672 KB
testcase_24 AC 7 ms
6,676 KB
testcase_25 AC 8 ms
6,676 KB
testcase_26 AC 108 ms
19,792 KB
testcase_27 AC 46 ms
8,456 KB
testcase_28 AC 76 ms
28,416 KB
testcase_29 AC 92 ms
52,224 KB
testcase_30 AC 126 ms
46,096 KB
testcase_31 AC 170 ms
35,996 KB
testcase_32 AC 205 ms
56,936 KB
testcase_33 AC 1,461 ms
135,812 KB
testcase_34 AC 625 ms
76,092 KB
testcase_35 AC 692 ms
71,140 KB
testcase_36 AC 373 ms
67,808 KB
testcase_37 TLE -
testcase_38 AC 579 ms
71,540 KB
testcase_39 AC 572 ms
79,964 KB
testcase_40 TLE -
testcase_41 AC 261 ms
60,928 KB
testcase_42 AC 831 ms
84,428 KB
testcase_43 AC 699 ms
82,016 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;
                    que.emplace(a[i][j] + 1, 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