結果
| 問題 |
No.2946 Puyo
|
| コンテスト | |
| ユーザー |
sorachandu
|
| 提出日時 | 2024-10-25 21:37:42 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 53 ms / 2,000 ms |
| コード長 | 5,392 bytes |
| コンパイル時間 | 3,220 ms |
| コンパイル使用メモリ | 257,912 KB |
| 実行使用メモリ | 24,960 KB |
| 最終ジャッジ日時 | 2024-10-25 21:37:54 |
| 合計ジャッジ時間 | 6,671 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 45 |
ソースコード
#if !__INCLUDE_LEVEL__
#include __FILE__
int main(){
int h,w;
cin>>h>>w;
vector<string> g(h);
rep(i,0,h)cin>>g[i];
// 場外判定
auto outof = [&](ull y, ull x){
return (y >= h || x >= w);
};
// 4方向の近傍 右,下,左,上
const int dy[4] = {0, 1, 0, -1};
const int dx[4] = {1, 0, -1, 0};
vector seen(h,vector<int>(w,0));
auto dfs=[&](auto self,int y,int x) -> int {
int cnt=1;
rep(i,0,4){
uint Y=y+dy[i],X=x+dx[i];
if(outof(Y,X) or g[y][x]!=g[Y][X] or seen[Y][X]) continue;
seen[Y][X]=true;
cnt+=self(self,Y,X);
}
return cnt;
};
auto upd=[&](auto self,int y,int x) -> void {
rep(i,0,4){
uint Y=y+dy[i],X=x+dx[i];
if(outof(Y,X) or g[y][x]!=g[Y][X] or seen[Y][X]==-1) continue;
seen[Y][X]=-1;
self(self,Y,X);
}
};
rep(i,0,h) rep(j,0,w){
if(!seen[i][j]){
seen[i][j]=true;
if(dfs(dfs,i,j)>=4){
seen[i][j]=-1;
upd(upd,i,j);
}
}
}
rep(i,0,h) rep(j,0,w){
if(seen[i][j]==-1) g[i][j]='.';
}
rep(i,0,h) cout<<g[i]<<el;
}
#else
#include <bits/stdc++.h>
using namespace std;
struct Init { Init() { ios::sync_with_stdio(0); cin.tie(0); cout << setprecision(13); } }init;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
#define rep(i, x, limit) for (ll i = (ll)x; i < (ll)limit; i++)
#define REP(i, x, limit) for (ll i = (ll)x; i <= (ll)limit; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define el '\n'
#define spa ' '
#define Yes cout << "Yes" << el
#define No cout << "No" << el
#define YES cout << "YES" << el
#define NO cout << "NO" << el
#define eps (1e-10)
#define Equals(a,b) (fabs((a) - (b)) < eps )
#define debug(x) cerr << #x << " = " << x << el
const double pi = 3.141592653589793238;
const int inf = 1073741823;
const ll infl = 1LL << 60;
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string abc = "abcdefghijklmnopqrstuvwxyz";
template<typename T1, typename T2>
std::ostream &operator<< (std::ostream &os, std::pair<T1,T2> p){
os << "{" << p.first << "," << p.second << "}";
return os;
}
// 配列の要素を空白区切りで出力 第二引数をtrueにすると改行区切り
template<typename T> inline void print_vec(const vector<T> &v, bool split_line=false) {
if(v.empty()){
cout << "This vector is empty." << el;
return;
}
constexpr bool isValue = is_integral<T>::value;
for (int i = 0; i < (int)v.size(); i++) {
if constexpr(isValue){
if((v[i]==inf) || (v[i]==infl)) cout << 'x' << " \n"[split_line || i+1==(int)v.size()];
else cout << v[i] << " \n"[split_line || i+1==(int)v.size()];
}else cout << v[i] << " \n"[split_line || i+1==(int)v.size()];
}
}
template<typename T1, typename T2> inline void print_vec(const vector<pair<T1,T2>> &v, bool split_line=false){
if(v.empty()){
cout << "This vector is empty." << el;
return;
}
for(int i = 0; i < (int)v.size(); i++){
cout << '{';
auto [a,b] = v[i];
constexpr pair<bool,bool> isValue = {is_integral<T1>::value, is_integral<T2>::value};
if constexpr(isValue.first){
if(a==inf || a==infl) cout << "x,";
else cout << a << ",";
}else cout << a << ",";
if constexpr(isValue.second){
if(b==inf || b==infl) cout << "x,";
else cout << b;
}else cout << b;
cout << "}" << " \n"[split_line || i+1==(int)v.size()];
}
}
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
bool compare = a < b;
if(compare) a = b;
return compare;
}
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
bool compare = a > b;
if(compare) a = b;
return compare;
}
// std::chronoを利用した時間計測用クラス
class Timer{
chrono::system_clock::time_point start;
public:
Timer() : start(chrono::system_clock::now()) {}
double count(){
chrono::duration<double> Time_ = chrono::system_clock::now() - start;
return Time_.count();
}
bool is_under(double x){
return (this -> count()) < x;
}
};
// std::uniform_int_distributionを利用した一様乱数生成クラス
class Random_Gen{
random_device seed_gen;
mt19937 engine;
uniform_int_distribution<int64_t> dist;
public:
// Constructor [l,r]で生成する値の範囲を指定
Random_Gen() : engine(seed_gen()) {}
Random_Gen(int64_t l, int64_t r) : engine(seed_gen()), dist(l,r) {}
// 現在の生成する値の範囲をstd::pairで返す
pair<int64_t,int64_t> get_range(){
return make_pair(dist.min(),dist.max());
}
// 生成する値の範囲を[l,r]に変更する
void set_range(int64_t l, int64_t r){
uniform_int_distribution<int64_t>::param_type Param(l,r);
dist.param(Param);
}
// [l,r]内の一様分布の整数を返す
int64_t gen(){
return dist(engine);
}
int64_t operator()(){ return gen(); }
};
#endif
sorachandu