#ifndef LOCAL
#define FAST_IO
#endif
// ===== template.hpp =====
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define OVERRIDE(a, b, c, d, ...) d
#define REP2(i, n) for (i32 i = 0; i < (i32) (n); ++i)
#define REP3(i, m, n) for (i32 i = (i32) (m); i < (i32) (n); ++i)
#define REP(...) OVERRIDE(__VA_ARGS__, REP3, REP2)(__VA_ARGS__)
#define PER(i, n) for (i32 i = (i32) (n) - 1; i >= 0; --i)
#define ALL(x) begin(x), end(x)
using namespace std;
using u32 = unsigned int;
using u64 = unsigned long long;
using u128 = __uint128_t;
using i32 = signed int;
using i64 = signed long long;
using i128 = __int128_t;
using f64 = double;
using f80 = long double;
template <typename T>
using Vec = vector<T>;
template <typename T>
bool chmin(T &x, const T &y) {
if (x > y) {
x = y;
return true;
}
return false;
}
template <typename T>
bool chmax(T &x, const T &y) {
if (x < y) {
x = y;
return true;
}
return false;
}
istream &operator>>(istream &is, i128 &x) {
i64 v;
is >> v;
x = v;
return is;
}
ostream &operator<<(ostream &os, i128 x) {
os << (i64) x;
return os;
}
istream &operator>>(istream &is, u128 &x) {
u64 v;
is >> v;
x = v;
return is;
}
ostream &operator<<(ostream &os, u128 x) {
os << (u64) x;
return os;
}
[[maybe_unused]] constexpr i32 INF = 1000000100;
[[maybe_unused]] constexpr i64 INF64 = 3000000000000000100;
#ifdef FAST_IO
__attribute__((constructor)) void fast_io() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(10);
}
#endif
// ===== template.hpp =====
#ifdef DEBUGF
#include "cpl/template/debug.hpp"
#else
#define DBG(x) (void) 0
#endif
int main() {
i32 n;
cin >> n;
Vec<i32> h(n);
REP(i, n) {
cin >> h[i];
}
if (n == 1) {
cout << 1 << '\n';
exit(0);
}
Vec<i32> idx(n);
iota(ALL(idx), 0);
sort(ALL(idx), [&](i32 i, i32 j) -> bool {
return h[i] < h[j];
});
i32 cnt = 1;
Vec<bool> alive(n, true);
i32 ans = cnt;
REP(i, n) {
i32 isl = idx[i];
if (isl == 0) {
if (!alive[isl + 1]) {
--cnt;
}
} else if (isl == n - 1) {
if (!alive[isl - 1]) {
--cnt;
}
} else {
if (alive[isl - 1] && alive[isl + 1]) {
++cnt;
} else if (!alive[isl - 1] && !alive[isl + 1]) {
--cnt;
}
}
alive[isl] = false;
if (i == n - 1 || h[idx[i]] != h[idx[i + 1]]) {
chmax(ans, cnt);
}
}
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
324 KB |
Output is correct |
4 |
Correct |
1 ms |
324 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
1364 KB |
Output is correct |
2 |
Correct |
10 ms |
1364 KB |
Output is correct |
3 |
Correct |
10 ms |
1364 KB |
Output is correct |
4 |
Correct |
11 ms |
1364 KB |
Output is correct |
5 |
Correct |
13 ms |
1348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
1860 KB |
Output is correct |
2 |
Correct |
14 ms |
1748 KB |
Output is correct |
3 |
Correct |
21 ms |
1856 KB |
Output is correct |
4 |
Correct |
21 ms |
1868 KB |
Output is correct |
5 |
Correct |
19 ms |
1868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
227 ms |
17496 KB |
Output is correct |
2 |
Correct |
228 ms |
17612 KB |
Output is correct |
3 |
Correct |
238 ms |
17612 KB |
Output is correct |
4 |
Correct |
247 ms |
17532 KB |
Output is correct |
5 |
Correct |
230 ms |
16904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
227 ms |
16892 KB |
Output is correct |
2 |
Correct |
230 ms |
16832 KB |
Output is correct |
3 |
Correct |
269 ms |
16836 KB |
Output is correct |
4 |
Correct |
114 ms |
11008 KB |
Output is correct |
5 |
Correct |
128 ms |
11112 KB |
Output is correct |