Skip to content

Instantly share code, notes, and snippets.

@BaekSeungYeol
Created December 19, 2019 05:34
Show Gist options
  • Save BaekSeungYeol/99dbcd3e07e4403e33f7602f43413689 to your computer and use it in GitHub Desktop.
Save BaekSeungYeol/99dbcd3e07e4403e33f7602f43413689 to your computer and use it in GitHub Desktop.
BOJ 16918
#include <iostream>
#include <string>
#include <vector>
using namespace std;
const int dy[4] = { 1,-1,0,0 };
const int dx[4] = { 0,0,1,-1 };
string a[200];
vector<vector<pair<int,int>>> v;
int r, c, n;
int main()
{
cin >> r >> c >> n;
for (int i = 0; i < r; ++i)
cin >> a[i];
v = vector < vector<pair<int, int>>>(r, vector<pair<int, int>>(c));
for (int i = 0; i < r; ++i)
for (int j = 0; j < c; ++j)
{
if (a[i][j] == '.') {
v[i][j].first = 0;
v[i][j].second = 0;
}
else {
v[i][j].first = 1;
v[i][j].second = 1;
}
}
int time = 1;
while (1) {
if (time == n) break;
time++;
//폭탄들 cnt 해주기
for (int i = 0; i < r; ++i)
for (int j = 0; j < c; ++j)
{
if (v[i][j].first == 1 && v[i][j].second >= 0)
v[i][j].second++;
}
//폭탄 설치
if (time % 2 == 0) {
for (int i = 0; i < r; ++i)
for (int j = 0; j < c; ++j)
if (v[i][j].first == 0) {
v[i][j].first = 1;
v[i][j].second = 0;
}
}
vector<vector<pair<int, int>>> temp(v);
//터뜨리기
for (int i = 0; i < r; ++i)
for (int j = 0; j < c; ++j)
{
if (v[i][j].second == 3) {
temp[i][j].first = 0;
temp[i][j].second = 0;
for (int k = 0; k < 4; ++k)
{
int ny = i + dy[k];
int nx = j + dx[k];
if (!(0 <= ny && ny < r && 0 <= nx && nx < c)) continue;
temp[ny][nx].first = 0;
temp[ny][nx].second = 0;
}
}
}
v = temp;
}
for (int i = 0; i < r; ++i) {
for (int j = 0; j < c; ++j)
{
if (v[i][j].first == 0) {
cout << '.';
}
else {
cout << 'O';
}
}
cout << "\n";
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment