SW Expert Academy - 1206. View

1 minute read

๋ฌธ์ œ๋งํฌ

๋ฌธ์ œ์„ค๋ช…

  • ๊ฐ•๋ณ€์— ๋นŒ๋”ฉ๋“ค์ด ์˜†์œผ๋กœ ๋นฝ๋นฝํ•˜๊ฒŒ ๋ฐ€์ง‘ํ•œ ์ง€์—ญ์ด ์žˆ๋‹ค.
  • ๋นŒ๋”ฉ์€ ์ตœ๋Œ€ 255์˜ ๋†’์ด๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๊ณ , ๋†’์ด 1๋‹น ํ•˜๋‚˜์˜ ๊ฐ€๊ตฌ๋ฅผ ์˜๋ฏธํ•œ๋‹ค.
  • ๊ฐ ์„ธ๋Œ€๊ฐ€ ์กฐ๋ง๊ถŒ์„ ํ™•๋ณดํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ์ขŒ์šฐ๋กœ 2์นธ ์ด์ƒ์˜ ๊ณต๋ฐฑ์ด ์กด์žฌํ•ด์•ผ ํ•œ๋‹ค.
  • ์กฐ๋ง๊ถŒ์ด ํ™•๋ณด๋œ ์„ธ๋Œ€์˜ ์ˆ˜๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜๋ผ

๋ฌธ์ œ์ ‘๊ทผ

  • ์ž…๋ ฅ ๋ฐ›๋Š” N๊ฐœ์˜ ๋นŒ๋”ฉ ์ค‘ ์ขŒ์šฐ 2์นธ์”ฉ(์ด 4์นธ)์€ ๋†’์ด๊ฐ€ ํ•ญ์ƒ 0์ด๋‹ค.
    • N๊ฐœ์˜ ์ž…๋ ฅ์— ํฌํ•จ๋˜๋Š” ๊ฒƒ์— ์ฃผ์˜ํ•˜์ž
  • ์ขŒ์šฐ๋กœ 2์นธ์”ฉ ๋นŒ๋”ฉ์˜ ๋†’์ด ์ฐจ์ด๋ฅผ ๋ชจ๋‘ ๊ตฌํ•œ๋‹ค.
  • 4๊ฐœ์˜ ๊ฐ’์ค‘ ํ•˜๋‚˜๋ผ๋„ ์Œ์ˆ˜์ธ ๊ฒฝ์šฐ ์กฐ๋ง๊ถŒ์„ ํ™•๋ณดํ•˜์ง€ ๋ชปํ•œ๋‹ค.
  • 4๊ฐœ์˜ ๊ฐ’์ด ๋ชจ๋‘ ์–‘์ˆ˜์ธ ๊ฒฝ์šฐ ์ตœ์†Ÿ๊ฐ’์ด ์กฐ๋ง๊ถŒ์ด ํ™•๋ณด๋œ ์„ธ๋Œ€ ์ˆ˜๊ฐ€ ๋œ๋‹ค.
  • ๋ชจ๋“  ๋นŒ๋”ฉ์— ๋Œ€ํ•ด ์œ„ ๋กœ์ง์„ ๋ฐ˜๋ณตํ•œ๋‹ค.

๊ตฌํ˜„

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(int argc, char** argv)
{
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
	int test_case;
	int T = 10;
	// freopen("input.txt", "r", stdin);
	for (test_case = 1; test_case <= T; ++test_case)
	{
		int N; // ๊ฑด๋ฌผ์˜ ๊ฐœ์ˆ˜ = ๊ฐ€๋กœ์˜ ๊ธธ์ด
		scanf("%d", &N);
		vector<int> building(N, 0);
		for (int i = 0; i < N; i++) {
			scanf("%d", &building[i]);
		}

		vector<int> diff(4, 0);
		int cnt = 0;
		for (int i = 2; i < N - 2; i++) {
			diff[0] = building[i] - building[i - 1];
			diff[1] = building[i] - building[i - 2];
			diff[2] = building[i] - building[i + 1];
			diff[3] = building[i] - building[i + 2];
			if ((diff[0] > 0) && (diff[1] > 0) && (diff[2] > 0) && (diff[3] > 0)) {
				cnt += *min_element(diff.begin(), diff.end());
			}
		}
		printf("#%d %d\n", test_case, cnt);
	}
	return 0;//์ •์ƒ์ข…๋ฃŒ์‹œ ๋ฐ˜๋“œ์‹œ 0์„ ๋ฆฌํ„ดํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค.
}

Categories:

Updated:

Leave a comment