Notice
Recent Posts
Recent Comments
Link
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Tags
- java
- ์ต๋จ ๊ฒฝ๋ก
- ๋์ ํฉ
- c++
- OS
- ๋ฐฑํธ๋ํน
- Spring
- ์์ ์ ๋ ฌ
- ์คํ
- JPA
- CVE
- ์ฌ๊ท
- thymeleaf
- ๋ถํ ์ ๋ณต
- error
- Reversing
- ๊ตฌํ
- dynamic debugging
- BFS
- ๋ฌธ์์ด
- ๋งต
- web
- ์ฐ์ ์์ ํ
- ์๋ฎฌ๋ ์ด์
- ๋ฐ์ดํฌ์คํธ๋ผ
- ๊ทธ๋ฆฌ๋
- ์ด๋ถ ํ์
- dfs
- DP
- GCP
Archives
- Today
- Total
hades
[Baekjoon] 7662๋ฒ: ์ด์ค ์ฐ์ ์์ ํ ๋ณธ๋ฌธ
๐ฅ ๋ฌธ์
https://www.acmicpc.net/problem/7662
๐ ์ค๊ณ
์ฒ์์ min_pq์ max_pq๋ง์ ๋ง๋ค์ด์ D์ผ ๋ n์ด ๋ฌด์์ด๋์ ๋ฐ๋ผ ํ์ชฝ์ผ๋ก ๋ชฐ์์ ์ฒ๋ฆฌํ๋ ๋ฐฉ์์ ํํ๋๋ฐ ์๊ฐ ์ด๊ณผ๊ฐ ๋ฐ์ํ๋ค. ๋ค๋ฅธ ๋ฐฉ๋ฒ์ ์ฐพ์์ผ ํ๋ค.
map์ ์ด์ฉํ์ฌ ๊ฐ์๋ฅผ ์ ์ฅํ๊ณ , D์ผ ๋, ์ญ์ ๋ฅผ ํ๊ธฐ ์ , ๋ค๋ฅธ ๋ช ๋ น์์ ๊ฐ์๊ฐ 0์ด ๋์์ ์๋ ์์ผ๋ฏ๋ก ๊ทธ ๊ฒฝ์ฐ๋ฅผ ๊ณ ๋ คํ์ฌ ์ญ์ ์ฒ๋ฆฌ๋ฅผ ํด์ฃผ์ด์ผ ํ๋ค. ์๋ฅผ ๋ค์ด D 1์ด์ด์ max_pq์์๋ ์ญ์ ํ์ง๋ง, min_pq์์๋ ์ญ์ ํ ์ ์์ผ๋ฏ๋ก ๋ฐ์๋์ง ์์๋ค. ๊ฐ์๋ง ๊ฐ์์ํค๊ณ , ์ญ์ ํ๋ ค๋ ์์ ๊ฐ์๊ฐ 0์ผ ๋, ๋ชจ๋ ์ญ์ ํ๋ค.
๐ ํ์ด
#include <iostream>
#include <queue>
#include <map>
using namespace std;
char ch;
int t, k, n;
int main(void)
{
cin >> t;
for (int i = 0; i < t; i++) {
cin >> k;
priority_queue<int, vector<int>, greater<int>> min_pq;
priority_queue<int> max_pq;
map<int, int> save;
for (int j = 0; j < k; j++) {
cin >> ch >> n;
if (ch == 'I') {
min_pq.push(n);
max_pq.push(n);
if (save.count(n) == 0){
save[n] = 1;
}
else{
save[n] += 1;
}
}
else {
if (n == 1) {
while (!max_pq.empty() && save[max_pq.top()] == 0){
max_pq.pop();
}
if (!max_pq.empty()){
save[max_pq.top()] -= 1;
max_pq.pop();
}
}
else {
while (!min_pq.empty() && save[min_pq.top()] == 0){
min_pq.pop();
}
if (!min_pq.empty()){
save[min_pq.top()] -= 1;
min_pq.pop();
}
}
}
}
while (!max_pq.empty() && save[max_pq.top()] == 0){
max_pq.pop();
}
while (!min_pq.empty() && save[min_pq.top()] == 0){
min_pq.pop();
}
if (max_pq.empty() && min_pq.empty()){
cout << "EMPTY" << "\n";
}
else{
cout << max_pq.top() << " " << min_pq.top() << "\n";
}
}
return 0;
}
'๐ PS > Algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Baekjoon] 10026๋ฒ: ์ ๋ก์์ฝ (2) | 2024.07.22 |
---|---|
[Baekjoon] 9095๋ฒ: 1, 2, 3 ๋ํ๊ธฐ (1) | 2024.07.20 |
[Baekjoon] 7569๋ฒ: ํ ๋งํ (0) | 2024.07.16 |
[Baekjoon] 5525๋ฒ: IOIOI (0) | 2024.07.15 |
[Baekjoon] 5430๋ฒ: AC (0) | 2024.07.15 |