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
- ์ฌ๊ท
- c++
- DP
- web
- ๋ฐฑํธ๋ํน
- JPA
- ์ด๋ถ ํ์
- BFS
- ์๋ฎฌ๋ ์ด์
- ๋ถํ ์ ๋ณต
- ๋ฌธ์์ด
- ์์ ์ ๋ ฌ
- error
- ์ต๋จ ๊ฒฝ๋ก
- ๋ฐ์ดํฌ์คํธ๋ผ
- ๋์ ํฉ
- java
- dynamic debugging
- OS
- Spring
- ๋งต
- ๊ทธ๋ฆฌ๋
- Reversing
- GCP
- CVE
- dfs
- ์คํ
- thymeleaf
- ์ฐ์ ์์ ํ
- ๊ตฌํ
Archives
- Today
- Total
hades
[Baekjoon] 2096๋ฒ: ๋ด๋ ค๊ฐ๊ธฐ ๋ณธ๋ฌธ
๐ฅ ๋ฌธ์
https://www.acmicpc.net/problem/2096
๐ ์ค๊ณ
์ ์ค๊น์ง์ ๊ฒฐ๊ณผ์ ์๋ก์ด ์ค์ ์ ๋ ฅ๋ฐ์ ์๋ฅผ ๋ํ์ฌ ์ต๋ ์ต์๋ฅผ ๊ตฌํ๋ ๋ค์ด๋๋ฏน ํ๋ก๊ทธ๋๋ฐ ๋ฌธ์ ์ด๋ค.
์ฒ์ ๋ฉ๋ชจ๋ฆฌ ์ ํ์ ๋ณด์ง ์๊ณ , 100000์ค์ ๋ค ๋ฐ์๋๋ฐ, ๋ฉ๋ชจ๋ฆฌ ์ด๊ณผ๊ฐ ๋ฐ์ํ์๋ค.
์๋ก์ด ์ค์ ์ ๋ ฅ๋ฐ์ ์์ ์ ์ค๊น์ง์ ์ ์, ์๋ก์ด ์ค๊น์ง์ ์ ์๋ง ํ์ํ๋ฏ๋ก ๋ฒกํฐ๋ฅผ 3๊ฐ๋ง ์์ฑํ๋ค.
๋ค์ด๋๋ฏน ํ๋ก๊ทธ๋๋ฐ์์๋ ์ด๊ธฐํ๊ฐ ํญ์ ์ค์ํ๋ฐ, ์ฒซ์งธ ์ค๊น์ง์ ์ ์๋ ์ ๋ ฅ๋ฐ์ ์ ๊ทธ๋๋ก์ด๋ค.
๐ ํ์ด
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n, col;
int dy[] = { -1,0,1 };
vector<int> new_line(3);
vector<pair<int, int>> before_score(3, { 0, 1e9 + 7 });
vector<pair<int, int>> new_score(3, { 0, 1e9 + 7 });
int main(void)
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for (int i = 0; i < 3; i++) {
cin >> new_line[i];
for (int j = 0; j < 3; j++) {
before_score[i].first = new_line[i];
before_score[i].second = new_line[i];
}
}
for (int i = 1; i < n; i++) {
for (int j = 0; j < 3; j++) {
cin >> new_line[j];
for (int k = 0; k < 3; k++) {
col = j + dy[k];
if (col >= 0 && col < 3) {
new_score[j].first = max(new_score[j].first, before_score[col].first + new_line[j]);
new_score[j].second = min(new_score[j].second, before_score[col].second + new_line[j]);
}
}
}
before_score = new_score;
new_score = vector<pair<int, int>> (3, { 0, 1e9 + 7 });
}
int max_result = 0;
int min_result = 1e9 + 7;
for (int i = 0; i < 3; i++) {
max_result = max(max_result, before_score[i].first);
min_result = min(min_result, before_score[i].second);
}
cout << max_result << " " << min_result << "\n";
return 0;
}
'๐ PS > Algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
15654๋ฒ: N๊ณผ M (5) (0) | 2024.08.12 |
---|---|
[Baekjoon] 9465๋ฒ: ์คํฐ์ปค (0) | 2024.08.11 |
[Baekjoon] 1987๋ฒ: ์ํ๋ฒณ (0) | 2024.08.09 |
[Baekjoon] 1918๋ฒ: ํ์ ํ๊ธฐ์ (0) | 2024.08.08 |
[Baekjoon] 11501๋ฒ: ์ฃผ์ (0) | 2024.08.07 |