結果

問題 No.2946 Puyo
ユーザー zawakasu
提出日時 2024-10-25 21:27:26
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 61 ms / 2,000 ms
コード長 1,187 bytes
コンパイル時間 959 ms
コンパイル使用メモリ 86,712 KB
最終ジャッジ日時 2025-02-24 22:47:12
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 45
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <cassert>
#include <vector>
#include <string>

int dx[4]{ 0, 1, 0, -1 }, dy[4]{ 1, 0, -1, 0 };

int main() {
    std::cin.tie(nullptr)->sync_with_stdio(false);

    int H, W;
    std::cin >> H >> W;
    std::vector<std::string> S(H);
    for (auto& s : S) std::cin >> s;
    std::vector vis(H, std::vector<bool>(W));
    auto in{[&](int x, int y) -> bool {
        return 0 <= x and x < H and 0 <= y and y < W;
    }};
    auto dfs{[&](auto dfs, int x, int y, std::vector<std::pair<int, int>>& vs) -> void {
        vs.push_back(std::pair{ x, y });
        vis[x][y] = true;
        for (int d{} ; d < 4 ; d++) {
            int nx{dx[d] + x}, ny{dy[d] + y};
            if (!in(nx, ny)) continue;
            if (vis[nx][ny]) continue;
            if (S[x][y] != S[nx][ny]) continue;
            dfs(dfs, nx, ny, vs);
        }
    }};
    for (int i{} ; i < H ; i++) for (int j{} ; j < W ; j++) if (!vis[i][j]) {
        std::vector<std::pair<int, int>> vs;
        dfs(dfs, i, j, vs);
        if (vs.size() >= 4u) {
            for (auto [x, y] : vs) S[x][y] = '.';
        }
    }
    for (const auto& s : S) std::cout << s << '\n';
}
0