結果
| 問題 |
No.2946 Puyo
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-10-25 21:40:04 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 87 ms / 2,000 ms |
| コード長 | 1,489 bytes |
| コンパイル時間 | 6,403 ms |
| コンパイル使用メモリ | 338,036 KB |
| 実行使用メモリ | 15,616 KB |
| 最終ジャッジ日時 | 2024-10-25 21:40:17 |
| 合計ジャッジ時間 | 10,466 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 45 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using ll = long long;
using ull = unsigned long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
random_device rnd;
mt19937 mt(rnd());
int RandInt(int a, int b) {
return a + mt() % (b - a + 1);
}
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
bool used[1010][1010];
int h,w;
vector<string> s;
int f(int x,int y,int cnt){
used[x][y]=true;
queue<pair<int,int>> q;
q.push({x,y});
while(!q.empty()){
auto [x,y]=q.front();q.pop();
rep(i,4){
int nx=x+dx[i];
int ny=y+dy[i];
if(nx<0||nx>=h||ny<0||ny>=w)continue;
if(used[nx][ny])continue;
if(s[nx][ny]=='.')continue;
if(s[x][y]!=s[nx][ny])continue;
cnt++;
used[nx][ny]=true;
q.push({nx,ny});
}
}
return cnt;
}
void f2(int x,int y,char c){
rep(i,4){
int nx=x+dx[i];
int ny=y+dy[i];
if(nx<0||nx>=h||ny<0||ny>=w)continue;
if(s[nx][ny]==c){
s[nx][ny]='.';
f2(nx,ny,c);
}
}
s[x][y]='.';
}
int main(){
cin>>h>>w;
s.resize(h);
rep(i,h) cin>>s[i];
rep(i,h)rep(j,w){
if(used[i][j])continue;
int cnt=f(i,j,1);
//cerr<<i<<" "<<j<<" "<<cnt<<endl;
if(cnt>=4)f2(i,j,s[i][j]);
}
rep(i,h)cout<<s[i]<<endl;
}