結果
| 問題 | No.2946 Puyo |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-10-26 00:58:50 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
AC
|
| 実行時間 | 65 ms / 2,000 ms |
| コード長 | 1,008 bytes |
| 記録 | |
| コンパイル時間 | 1,261 ms |
| コンパイル使用メモリ | 227,600 KB |
| 実行使用メモリ | 9,232 KB |
| 最終ジャッジ日時 | 2026-07-06 01:58:47 |
| 合計ジャッジ時間 | 6,807 ms |
|
ジャッジサーバーID (参考情報) |
judge2_1 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 45 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main(){
int H, W;
cin >> H >> W;
vector<string> G(H);
for (int i = 0; i < H; i++){
cin >> G[i];
}
vector<vector<bool>> vis(H, vector<bool>(W));
for (int i = 0; i < H; i++){
for (int j = 0; j < W; j++){
if (vis[i][j]){
continue;
}
queue<pair<int, int>> q;
q.push(make_pair(i, j));
vector<pair<int, int>> A;
A.push_back(make_pair(i, j));
vis[i][j] = true;
while (!q.empty()){
auto [x, y] = q.front();
q.pop();
for (int k = 0; k < 4; k++){
int px = x + dx[k], py = y + dy[k];
if (0 <= px and px < H and 0 <= py and py < W and !vis[px][py]){
if (G[px][py] == G[i][j]){
q.push(make_pair(px, py));
A.push_back(make_pair(px, py));
vis[px][py] = true;
}
}
}
}
if (A.size() >= 4){
for (auto [x, y] : A){
G[x][y] = '.';
}
}
}
}
for (int i = 0; i < H; i++){
cout << G[i] << endl;
}
}