結果
| 問題 |
No.2946 Puyo
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-10-25 21:35:29 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 154 ms / 2,000 ms |
| コード長 | 1,314 bytes |
| コンパイル時間 | 2,439 ms |
| コンパイル使用メモリ | 210,844 KB |
| 最終ジャッジ日時 | 2025-02-24 22:50:32 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 45 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main(){
cin.tie(nullptr)->sync_with_stdio(false);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#endif
int N, M; cin >> N >> M;
vector<string> grid(N);
for(auto& row: grid) cin >> row;
vector vis(N, vector(M, false));
const int dirs[] = {0, 1, 0, -1, 0};
for(int i = 0; i < N; ++i){
for(int j = 0; j < M; ++j){
if(!vis[i][j]){
char c = grid[i][j];
vis[i][j] = true;
queue<pair<int, int>> q{{{i, j}}};
vector<pair<int, int>> tmp;
while(!q.empty()){
auto [x, y] = q.front();
// print__(x, y);
tmp.emplace_back(x, y);
q.pop();
for(int k = 0; k < 4; ++k){
const int nx = x + dirs[k];
const int ny = y + dirs[k + 1];
if(nx < 0 || ny < 0 || nx == N || ny == M) continue;
if(vis[nx][ny] || grid[nx][ny] != c) continue;
vis[nx][ny] = true;
q.emplace(nx, ny);
}
}
// print__("________________________");
if(tmp.size() >= 4){
for(const auto& [x, y]: tmp){
grid[x][y] = '.';
}
}
}
}
}
for(auto& row: grid) cout << row << '\n';
return 0;
}