hades

[Baekjoon] 2096๋ฒˆ: ๋‚ด๋ ค๊ฐ€๊ธฐ ๋ณธ๋ฌธ

๐Ÿ‘Š PS/Algorithm

[Baekjoon] 2096๋ฒˆ: ๋‚ด๋ ค๊ฐ€๊ธฐ

hades1 2024. 8. 10. 20:10

๐Ÿฅ… ๋ฌธ์ œ

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