結果
| 問題 |
No.2946 Puyo
|
| コンテスト | |
| ユーザー |
hatsuka_iwa
|
| 提出日時 | 2024-11-11 03:43:42 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 78 ms / 2,000 ms |
| コード長 | 1,383 bytes |
| コンパイル時間 | 2,384 ms |
| コンパイル使用メモリ | 209,324 KB |
| 最終ジャッジ日時 | 2025-02-25 03:42:13 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 45 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main() {
int H, W; cin >> H >> W;
vector<int> dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vector<string> G(H); for (string &S : G) cin >> S;
vector seen(H, vector<bool>(W));
queue<pair<int, int>> Q;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
if (G.at(i).at(j) == '.') continue;
int Count = 0;
char A = G.at(i).at(j);
Q.push({i, j});
seen.at(i).at(j) = true;
while (!Q.empty()){
Count++;
int y = Q.front().first, x = Q.front().second;
Q.pop();
for (int k = 0; k < 4; k++) {
int ny = y + dy.at(k), nx = x + dx.at(k);
if (ny < 0 || ny >= H || nx < 0 || nx >= W || seen.at(ny).at(nx) || G.at(ny).at(nx) != A) continue;
Q.push({ny, nx});
seen.at(ny).at(nx) = true;
}
}
if (Count > 3) {
Q.push({i, j});
G.at(i).at(j) = '.';
while (!Q.empty()) {
int y = Q.front().first, x = Q.front().second;
Q.pop();
for (int k = 0; k < 4; k++) {
int ny = y + dy.at(k), nx = x + dx.at(k);
if (ny < 0 || ny >= H || nx < 0 || nx >= W || G.at(ny).at(nx) != A) continue;
Q.push({ny, nx});
G.at(ny).at(nx) = '.';
}
}
}
}
}
for (string S : G) cout << S << endl;
}
hatsuka_iwa