結果
| 問題 |
No.2946 Puyo
|
| コンテスト | |
| ユーザー |
ManjushriMitra
|
| 提出日時 | 2024-11-28 18:13:00 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 47 ms / 2,000 ms |
| コード長 | 2,133 bytes |
| コンパイル時間 | 3,463 ms |
| コンパイル使用メモリ | 252,820 KB |
| 実行使用メモリ | 12,160 KB |
| 最終ジャッジ日時 | 2024-11-28 18:13:11 |
| 合計ジャッジ時間 | 8,741 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 45 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,m,n) for(int i=m; i<int(n); ++i)
#define repll(i,m,n) for(ll i=m; i<ll(n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define fi first
#define se second
template<typename T> bool chmin(T& a, T b){ if(a > b){a = b; return true;} return false; }
template<typename T> bool chmax(T& a, T b){ if(a < b){a = b; return true;} return false; }
template<typename T> T gcd(T a, T b){ return a % b ? gcd(b, a % b) : b; }
template<typename T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
const int dy[4] = {1, 0, -1, 0};
const int dx[4] = {0, 1, 0, -1};
struct UnionFind{
vector<int> siz, parent;
UnionFind(){}
UnionFind(int n){
siz.resize(n, 0);
parent.resize(n, 0);
for(int i=0; i<n; ++i){
make_tree(i);
}
}
void make_tree(int x){
parent[x] = x;
siz[x] = 1;
}
bool is_same(int x, int y){
return find_root(x) == find_root(y);
}
bool unite(int x, int y){
x = find_root(x);
y = find_root(y);
if(x == y) return false;
if(siz[x] > siz[y]){
parent[y] = x;
siz[x] += siz[y];
}else{
parent[x] = y;
siz[y] += siz[x];
}
return true;
}
int find_root(int x){
if(x != parent[x]) parent[x] = find_root(parent[x]);
return parent[x];
}
int tree_size(int x){
return siz[find_root(x)];
}
};
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int H, W;
cin >> H >> W;
vector<string> G(H);
rep(y, 0, H) cin >> G[y];
UnionFind UF(H*W);
rep(y, 0, H) rep(x, 0, W) rep(d, 0, 4){
int ny = y + dy[d], nx = x + dx[d];
if(!(0 <= ny && ny < H && 0 <= nx && nx < W)) continue;
if(G[y][x] == G[ny][nx]) UF.unite(y*W + x, ny*W + nx);
}
rep(y, 0, H){
rep(x, 0, W){
if(UF.tree_size(y*W + x) >= 4) cout << '.';
else cout << G[y][x];
}
cout << endl;
}
return 0;
}
ManjushriMitra