// 상하좌우
IntPair dir[]
{
{ 1, 0 },
{-1, 0 },
{ 0, -1 },
{ 0, 1 }
};
vector<string> bomberMan(int n, vector<string> grid)
{
vector<pair<int, int>> pos;
int r = grid.size(), c = grid[r - 1].size();
if (0 == n % 2)
{
for (int y = 0; y < grid.size(); ++y)
for (int x = 0; x < grid[y].size(); ++x)
grid[y][x] = 'O';
return grid;
}
else if ((n + 1) % 4 == 0)
n = 3;
else if (n != 1 && (n - 1) % 4 == 0)
n = 5;
for (int t = 2; t <= n; ++t)
{
if (0 == t % 2)
{
for (int y = 0; y < grid.size(); ++y)
{
for (int x = 0; x < grid[y].size(); ++x)
{
if (grid[y][x] == 'O')
pos.push_back({ y, x });
else
grid[y][x] = 'O';
}
}
}
else
{
for (int i = 0; i < pos.size(); ++i)
{
int y = pos[i].first, x = pos[i].second;
grid[y][x] = '.';
for (int i = 0; i < 4; i++)
{
int ny = y + dir[i].first, nx = x + dir[i].second;
if (ny >= 0 &&
ny < r)
grid[ny][x] = '.';
if (nx >= 0 &&
nx < c)
grid[y][nx] = '.';
}
}
pos.clear();
}
}
return grid;
}