結果

問題 No.2946 Puyo
ユーザー hatsuka_iwa
提出日時 2024-11-11 01:38:05
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
MLE  
実行時間 -
コード長 1,315 bytes
コンパイル時間 2,494 ms
コンパイル使用メモリ 209,388 KB
最終ジャッジ日時 2025-02-25 03:32:06
ジャッジサーバーID
(参考情報)
judge4 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25 MLE * 1 -- * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
  int H, W; cin >> H >> W;
  vector<int> dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
  vector<string> G(H); for (string &S : G) cin >> S;
  vector seen(H, vector<bool>(W));
  queue<pair<int, int>> Q;

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {

      if (G.at(i).at(j) == '.') continue;
      int Count = 0;
      char A = G.at(i).at(j);
      Q.push({i, j});

      while (!Q.empty()){
        Count++;
        int y = Q.front().first, x = Q.front().second;
        seen.at(y).at(x) = true;
        Q.pop();
        for (int k = 0; k < 4; k++) {
          int ny = y + dy.at(k), nx = x + dx.at(k);
          if (ny < 0 || ny >= H || nx < 0 || nx >= W || seen.at(ny).at(nx) || G.at(ny).at(nx) != A) continue;
          Q.push({ny, nx});
        }
      }

      if (Count > 3) {
        Q.push({i, j});
        while (!Q.empty()) {
          int y = Q.front().first, x = Q.front().second;
          G.at(y).at(x) = '.';
          Q.pop();
          for (int k = 0; k < 4; k++) {
            int ny = y + dy.at(k), nx = x + dx.at(k);
            if (ny < 0 || ny >= H || nx < 0 || nx >= W || G.at(ny).at(nx) != A) continue;
            Q.push({ny, nx});
          }
        }
      }

    }
  }

  for (string S : G) cout << S << endl;
}
0