#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
vector<int> h(n);
vector<pair<int, int>> hsort(n);
vector<bool> present(n, true);
for (int i = 0; i < n; ++i) {
cin >> h[i];
hsort[i].first = h[i];
hsort[i].second = i;
}
sort(hsort.begin(), hsort.end());
if (n == 1) {
cout << "1\n";
return 0;
}
int ans = 1, isl = 1;
for (int i = 0; i < n; ++i) {
if (i != 0 && hsort[i].first != hsort[i - 1].first) {
ans = max(ans, isl);
}
int idx = hsort[i].second;
present[idx] = false;
if (idx == 0) {
isl -= !present[1];
continue;
}
if (idx == n - 1) {
isl -= !present[n - 2];
continue;
}
if (!present[idx - 1] && !present[idx + 1]) {
isl--;
continue;
}
if (present[idx - 1] && present[idx + 1]) {
isl++;
continue;
}
}
ans = max(ans, isl);
cout << ans << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
1656 KB |
Output is correct |
2 |
Correct |
13 ms |
1628 KB |
Output is correct |
3 |
Correct |
18 ms |
1656 KB |
Output is correct |
4 |
Correct |
15 ms |
1628 KB |
Output is correct |
5 |
Correct |
13 ms |
1628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
1660 KB |
Output is correct |
2 |
Correct |
12 ms |
1648 KB |
Output is correct |
3 |
Correct |
16 ms |
1628 KB |
Output is correct |
4 |
Correct |
13 ms |
1660 KB |
Output is correct |
5 |
Correct |
13 ms |
1624 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
158 ms |
12120 KB |
Output is correct |
2 |
Correct |
159 ms |
21588 KB |
Output is correct |
3 |
Correct |
161 ms |
21664 KB |
Output is correct |
4 |
Correct |
153 ms |
21588 KB |
Output is correct |
5 |
Correct |
149 ms |
20888 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
162 ms |
12124 KB |
Output is correct |
2 |
Correct |
164 ms |
12124 KB |
Output is correct |
3 |
Correct |
158 ms |
12124 KB |
Output is correct |
4 |
Correct |
137 ms |
12124 KB |
Output is correct |
5 |
Correct |
137 ms |
12120 KB |
Output is correct |