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
- Spring
- BFS
- ์ต๋จ ๊ฒฝ๋ก
- ๋ฐฑํธ๋ํน
- ์ด๋ถ ํ์
- dynamic debugging
- ๋ถํ ์ ๋ณต
- ๊ทธ๋ฆฌ๋
- DP
- ๋งต
- ๊ตฌํ
- ์์ ์ ๋ ฌ
- ๋ฌธ์์ด
- CVE
- ๋ฐ์ดํฌ์คํธ๋ผ
- Reversing
- c++
- ๋์ ํฉ
- thymeleaf
- OS
- java
- ์คํ
- ์ฐ์ ์์ ํ
- web
- dfs
- ์ฌ๊ท
- GCP
- JPA
- ์๋ฎฌ๋ ์ด์
- error
Archives
- Today
- Total
hades
[Baekjoon] 30804๋ฒ: ๊ณผ์ผ ํํ๋ฃจ ๋ณธ๋ฌธ
๐ฅ ๋ฌธ์
https://www.acmicpc.net/problem/30804
๐ ์ค๊ณ
๊ผฌ์น์ ๊ณผ์ผ์ ๋ชจ๋ ๊ฝ์๋๊ณ ์๋์์ ๋นผ๋ ๊ฒ์ ์์์๋ถํฐ ํ๋์ฉ ๋ผ์ฐ๊ณ ๊ฝํ ๊ณผ์ผ์ ์ข ๋ฅ๊ฐ 2๊ฐ๋ฅผ ๋์ผ๋ฉด ์์ ์๋ ๊ณผ์ผ์ ๋นผ๋ ๊ฒ๊ณผ ๊ฐ๋ค. ์์ง ๊ฝํ์ง ์์ ๊ณผ์ผ๋ค์ ๋บ๋ค๊ณ ์๊ฐํ๋ฉด ๋๊ธฐ ๋๋ฌธ์ด๋ค.
๊ณผ์ผ์ ํ๋์ฉ ๋ผ์ฐ๊ณ , ๊ผฌ์น์ ํ์ฌ ์๋ ๊ณผ์ผ์ด๋ผ๋ฉด ๊ณผ์ผ์ ์ข ๋ฅ๋ฅผ ํ๋ ์ฆ๊ฐ์ํจ๋ค. ๊ผฌ์น์ ๊ฝํ์๋ ๊ณผ์ผ์ ์ข ๋ฅ๊ฐ 2๊ฐ๋ฅผ ์ด๊ณผํ๋ค๋ฉด, 2๊ฐ๊ฐ ๋ ๋๊น์ง ์์์๋ถํฐ ๋บ๋ค. 2๊ฐ๊ฐ ๋์์ผ๋ฉด ๊ฒฐ๊ณผ๊ฐ์ ๊ฐฑ์ ํ๋ค.
๐ ํ์ด
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
int n, fruit, type = 0, result = 0;
vector<int> fruit_count(10);
queue<int> stick;
int main(void)
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> fruit;
stick.push(fruit);
if (fruit_count[fruit] == 0) {
type += 1;
}
fruit_count[fruit] += 1;
while (type > 2) {
int front_fruit = stick.front();
stick.pop();
fruit_count[front_fruit] -= 1;
if (fruit_count[front_fruit] == 0) {
type -= 1;
}
}
result = max(result,(int)stick.size());
}
cout << result << "\n";
return 0;
}
'๐ PS > Algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Baekjoon] 1043๋ฒ: ๊ฑฐ์ง๋ง (0) | 2024.08.01 |
---|---|
[Baekjoon] 28702๋ฒ: FizzBuzz (0) | 2024.07.31 |
[Baekjoon] 17626๋ฒ: Four Squares (0) | 2024.07.29 |
[Baekjoon] 14500๋ฒ: ํ ํธ๋ก๋ฏธ๋ ธ (1) | 2024.07.26 |
[Baekjoon] 11726๋ฒ: 2xn ํ์ผ๋ง (0) | 2024.07.26 |