-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhike.cpp
71 lines (58 loc) · 1.4 KB
/
hike.cpp
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
65
66
67
68
69
70
71
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pi = pair<ll, ll>;
using vi = vector<ll>;
using vpi = vector<pi>;
using vb = vector<bool>;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n;
cin >> n;
vi a(n);
for(ll i = 0; i < n; i++) {
cin >> a[i];
}
ll num_l = 0;
ll best = 0;
array<ll, 2> best_is;
for (ll it = 0; it < 2; it++) {
// find len of longest monotone segment
ll curr = 1;
for (ll i = 0; i < n; i++) {
if(curr >= best) {
best = curr;
}
if (i == n - 1) break;
if (a[i + 1] > a[i])
curr++;
else
curr = 1;
}
reverse(a.begin(), a.end());
}
for (ll it = 0; it < 2; it++) {
// find len of longest monotone segment
ll curr = 1;
for (ll i = 0; i < n; i++) {
if (curr == best) {
best_is[it] = i;
num_l++;
}
if (i == n - 1) break;
if (a[i + 1] > a[i])
curr++;
else
curr = 1;
}
reverse(a.begin(), a.end());
}
best_is[1] = n - 1 - best_is[1];
if (num_l != 2 || best_is[0] != best_is[1] || best % 2 != 1) {
cout << 0 << endl;
return 0;
}
cout << 1 << endl;
return 0;
}