103642024-04-01 11:53:42MagyarKendeSZLGVölgy (100 pont)cpp17Accepted 100/10017ms12236 KiB
// thanks to the creative genius of TomaSajt
#include <bits/stdc++.h>

#define cinv(v) for (auto& e : v) cin >> e;
#define all(v) v.begin(), v.end()
#define has(s, e) s.count(e)

using namespace std;
using ll = long long;

int N;
int solve(const vector<int>& v) {
    vector<int> prev(N, -1);
    int result = 0;
    for (int i = 0; i < N; i++) {
        prev[i] = i - 1;
        while (prev[i] != -1 && v[prev[i]] < v[i]) {
            prev[i] = prev[prev[i]];
        }
        if (prev[i] != -1) {
            result = max(result, i - prev[i]);
        }
    }
    return result;
}

int main() {
    cin.tie(0); ios::sync_with_stdio(0);
    cin >> N;

    vector<int> u(N), v;
    cinv(u);
    v = u;
    reverse(all(v));

    int result = max(solve(u), solve(v));
    cout << (result <= 1 ? -1 : result);
}
SubtaskSumTestVerdictTimeMemory
base100/100
1Accepted0/03ms1828 KiB
2Accepted0/03ms2196 KiB
3Accepted5/53ms2272 KiB
4Accepted5/53ms2488 KiB
5Accepted5/53ms2688 KiB
6Accepted5/53ms2896 KiB
7Accepted5/53ms3104 KiB
8Accepted5/53ms3340 KiB
9Accepted5/53ms3428 KiB
10Accepted5/53ms3428 KiB
11Accepted5/53ms3736 KiB
12Accepted5/54ms4224 KiB
13Accepted5/54ms4448 KiB
14Accepted5/54ms4728 KiB
15Accepted5/517ms7424 KiB
16Accepted5/517ms7988 KiB
17Accepted5/514ms8568 KiB
18Accepted5/516ms9072 KiB
19Accepted5/514ms9776 KiB
20Accepted5/516ms10624 KiB
21Accepted5/517ms11532 KiB
22Accepted5/517ms12236 KiB