-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4796.cpp
More file actions
64 lines (60 loc) · 1.04 KB
/
4796.cpp
File metadata and controls
64 lines (60 loc) · 1.04 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// 4796. 의석이의 우뚝 선 산
// 2019.07.08
#include<iostream>
#include<vector>
using namespace std;
int main()
{
int t;
cin >> t;
for (int testCase = 1; testCase <= t; testCase++)
{
int n;
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; i++)
{
cin >> v[i];
}
int ans = 0;
for (int i = 1; i < n - 1; i++)
{
if (v[i - 1] < v[i] && v[i] > v[i + 1])
{
int left = i - 1;
int right = i + 1;
int leftCnt = 1;
int rightCnt = 1;
while (left > 0)
{
left--;
if (v[left + 1] > v[left])
{
leftCnt++;
}
else
{
break;
}
}
while (right < n - 1)
{
right++;
if (v[right - 1] > v[right])
{
rightCnt++;
}
else
{
break;
}
}
// 우뚝 설 수 있는 구간의 개수 더함
// 왼쪽으로 작은 수 * 오른쪽으로 작은 수 가지의 경우의 수가 존재하므로 곱을 더한다.
ans += leftCnt * rightCnt;
}
}
cout << "#" << testCase << " " << ans << endl;
}
return 0;
}