結果

問題 No.179 塗り分け
ユーザー Zettsu Tatsuya
提出日時 2023-11-29 20:37:56
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 73 ms / 3,000 ms
コード長 2,308 bytes
コンパイル時間 1,922 ms
コンパイル使用メモリ 196,740 KB
最終ジャッジ日時 2025-02-18 02:24:42
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/modint>

namespace {
using ModInt [[maybe_unused]] = atcoder::modint998244353;
using Num [[maybe_unused]] = long long int;
using Vec [[maybe_unused]] = std::vector<Num>;
using Set [[maybe_unused]] = std::set<Num>;
using Mset [[maybe_unused]] = std::multiset<Num>;
using Edges [[maybe_unused]] = std::vector<std::vector<Num>>;

template<typename T>
using Q [[maybe_unused]] = std::queue<T>;

template<typename T>
using PQ [[maybe_unused]] = std::priority_queue<T, std::vector<T>, std::greater<T>>;
}

using Grid = std::array<std::array<Num, 50>, 50>;

void solve(std::istream& is, std::ostream& os) {
    Num h {0};
    Num w {0};
    is >> h >> w;

    Grid base;
    for(Num y{0}; y<h; ++y) {
        std::string s;
        is >> s;
        for(Num x{0}; x<w; ++x) {
            base[y][x] = s.at(x) == '#';
        }
    }

    for(Num dy{-h+1}; dy<h; ++dy) {
        for(Num dx{-w+1}; dx<w; ++dx) {
            if ((dy == 0) && (dx == 0)) {
                continue;
            }

            auto g = base;
            bool failed {false};
            for(Num y{0}; !failed && (y<h); ++y) {
                const auto ty = dy + y;

                for(Num x{0}; !failed && (x<w); ++x) {
                    const auto tx = dx + x;

                    if (g[y][x] == 0) {
                        continue;
                    }

                    if (g[y][x] == 1) {
                        if ((ty < 0) || (tx < 0) || (ty >= h) || (tx >= w) || (g[ty][tx] != 1)) {
                            failed = true;
                            break;
                        }
                        g[y][x] = 2;
                        g[ty][tx] = 3;
                    }
                }
            }

            Num ct2 {0};
            Num ct3 {0};
            for(Num y{0}; !failed && (y<h); ++y) {
                for(Num x{0}; !failed && (x<w); ++x) {
                    failed |= (g[y][x] == 1);
                    ct2 |= (g[y][x] == 2);
                    ct3 |= (g[y][x] == 3);
                }
            }

            if (!failed && (ct2 > 0) && (ct3 > 0)) {
                os << "YES\n";
                return;
            }
        }
    }

    os << "NO\n";
    return;
}

int main(void) {
    solve(std::cin, std::cout);
    return 0;
}
0