結果

問題 No.2946 Puyo
ユーザー achapiachapi
提出日時 2024-10-26 00:58:50
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 116 ms / 2,000 ms
コード長 1,008 bytes
コンパイル時間 2,481 ms
コンパイル使用メモリ 216,432 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-26 00:58:57
合計ジャッジ時間 6,835 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 45
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
	}
}
0