19638 - 센티와 마법의 뿅망치
2025. 3. 10. 15:55ㆍPS/백준
문제
https://www.acmicpc.net/problem/19638
느낀점
구현 기본 문제, 문제에 나와있는대로 키가 큰 순서대로 망치를 때려주어야해서 일반적인 선형 자료 구조는 못 풀고, 힙으로 풀었다.
풀이
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int N, H, T;
cin >> N >> H >> T;
vector<int> giant(N);
int initT = T;
for (int i = 0; i < N; i++)
{
cin >> giant[i];
}
bool check = false;
make_heap(giant.begin(), giant.end());
while (1)
{
pop_heap(giant.begin(), giant.end());
auto top = giant.back();
if (top < H)
{
check = true;
break;
}
if (T <= 0 || top == 1)
{
check = false;
break;
}
giant.pop_back();
top /= 2;
giant.push_back(top);
push_heap(giant.begin(), giant.end());
T--;
}
if (check)
{
cout << "YES" << "\n";
cout << initT - T;
}
else
{
cout << "NO" << "\n";
cout << *max_element(giant.begin(), giant.end());
}
return 0;
}
'PS > 백준' 카테고리의 다른 글
21314 - 민겸 수 00 | 2025.03.12 |
---|---|
17276 - 배열 돌리기 00 | 2025.03.08 |
16924 - 십자가 찾기 00 | 2025.03.07 |
16918 - 봄버맨 00 | 2025.03.06 |
9081 - 단어 맞추기 00 | 2025.03.05 |