結果

問題 No.2946 Puyo
ユーザー miiitomi
提出日時 2024-10-25 21:28:01
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 1,822 bytes
コンパイル時間 3,175 ms
コンパイル使用メモリ 253,180 KB
実行使用メモリ 12,136 KB
最終ジャッジ日時 2024-10-25 21:28:15
合計ジャッジ時間 6,132 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 45
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 2e+18;
const ll MOD = 998244353;
struct UnionFind {
vector<int> par, siz;
UnionFind(int n) : par(n, -1), siz(n, 1) {}
int root(int x) {
if (par[x] == -1) return x;
else return par[x] = root(par[x]);
}
bool issame(int x, int y) {
return root(x) == root(y);
}
bool unite(int x, int y) {
x = root(x);
y = root(y);
if (x == y) return false;
if (siz[x] < siz[y]) swap(x, y);
par[y] = x;
siz[x] += siz[y];
return true;
}
int size(int x) {
return siz[root(x)];
}
};
int H, W;
vector<int> dx{1, -1, 0, 0}, dy{0, 0, 1, -1};
bool is_in(int x, int y) {return 0 <= x && x < H && 0 <= y && y < W;}
int to_int(int x, int y) {return x*W + y;}
pair<int,int> to_xy(int i) {return make_pair(i/W, i%W);}
void solve() {
cin >> H >> W;
vector<string> G(H);
for (int i = 0; i < H; i++) cin >> G[i];
UnionFind uf(H*W);
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
if (G[i][j] == '.') continue;
int x = to_int(i, j);
for (int k = 0; k < 4; k++) {
int s = i + dx[k], t = j + dy[k];
if (!is_in(s, t) || G[i][j] != G[s][t]) continue;
uf.unite(x, to_int(s, t));
}
}
}
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
int u = to_int(i, j);
if (uf.size(uf.root(u)) < 4) continue;
G[i][j] = '.';
}
}
for (auto &s : G) cout << s << "\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(15);
int T = 1;
// cin >> T;
while (T--) solve();
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0