https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWXRJ8EKe48DFAUo
#include <iostream>
#include <vector>
#include <cstring>
#include <queue>
using namespace std;
const int MAX = 350;
int n, m, K;
int map[MAX][MAX];
struct MOVE { int x, y; };
MOVE mv[4] = { {1,0}, {-1,0}, {0,1}, {0,-1} };
struct INFO { int x, y, ori,cur; };
struct cmp{
bool operator()(INFO a, INFO b) {
if (a.ori < b.ori) return true;
else return false;
}
};
int main(void) {
int testcase;
cin >> testcase;
int index = 1;
for (; testcase > 0; testcase--) {
cin >> n >> m >> K;
memset(map, 0, sizeof(map));
vector<INFO> cells;
priority_queue<INFO,vector<INFO>, cmp> activation;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
int v;
cin >> v;
map[150 + i][150 + j] = v;
if (v != 0) cells.push_back({ 150 + i,150 + j,v,v });
}
}
int dead = 0;
int len = cells.size();
while (K > 0) {
K--;
for (int i = 0; i < len; i++) {
cells[i].cur--;
if (cells[i].cur == -1) {
activation.push(cells[i]);
}
if (cells[i].cur == -cells[i].ori) {
dead++;
}
}
while (!activation.empty()) {
int ii = activation.top().x;
int jj = activation.top().y;
int c = activation.top().ori;
activation.pop();
for (int k = 0; k < 4; k++) {
int movei = ii + mv[k].x;
int movej = jj + mv[k].y;
if (map[movei][movej] == 0) {
map[movei][movej] = c;
cells.push_back({ movei,movej,c,c });
len++;
}
}
}
}
cout << "#" << index << " " << len-dead << "\n";
index++;
}
}
'백준 알고리즘 > 구현' 카테고리의 다른 글
특이한 자석 C++ (0) | 2022.04.23 |
---|---|
활주로 건설 C++ (0) | 2022.04.23 |
로봇 시뮬레이션 C++ (0) | 2022.03.09 |
스위치 켜고 끄기 (0) | 2022.03.08 |
치즈 C++ (0) | 2022.03.07 |