結果

問題 No.2946 Puyo
ユーザー forest3
提出日時 2025-02-08 13:54:21
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 263 ms / 2,000 ms
コード長 880 bytes
コンパイル時間 1,539 ms
コンパイル使用メモリ 174,220 KB
実行使用メモリ 12,160 KB
最終ジャッジ日時 2025-02-08 13:54:33
合計ジャッジ時間 9,837 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 45
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define rep(i, n) for(int i = 0; i < n; i++ )
using ll = long long;

int main() {
	int H, W;
	cin >> H >> W;
	vector<string> s(H);
	rep(i, H) cin >> s[i];
	vector<int> dy{1, -1, 0, 0}, dx{0, 0, 1, -1};
	rep(i, H) rep(j, W) {
		char c = s[i][j];
		if(c == '.') continue;
		queue<int> q;
		int t = i * W + j;
		set<int> st;
		st.insert(t);
		q.push(t);
		while(q.size()) {
			int u = q.front();
			q.pop();
			int y = u / W;
			int x = u % W;
			rep(k, 4) {
				int ny = y + dy[k];
				int nx = x + dx[k];
				if(ny < 0 || ny >= H || nx < 0 || nx >= W) continue;
				if(s[ny][nx] != c) continue;
				t = ny * W + nx;
				if(st.count(t)) continue;
				st.insert(t);
				q.push(t);
			}
		}
		if(st.size() > 3) {
			for(int e : st) {
				int y = e / W;
				int x = e % W;
				s[y][x] = '.';
			}
		}
	}
	rep(i, H) cout << s[i] << endl;
}
0