235212026-01-24 11:06:58BoldizsárVölgy (100 pont)cpp17Accepted 100/10037ms1076 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
	int n;cin >> n;
    int ans =0;
    stack<int>volgy;
    vector<int>index(n);
    for(int i = 0;i < n;i++) cin >> index[i];
    for(int i = 0;i < n;i++){
        while(!volgy.empty() && index[volgy.top()] < index[i]){
            ans = max(ans,abs(volgy.top()-i));
            volgy.pop();
        }
        if(!volgy.empty()) ans = max(ans,abs(i-volgy.top()));
        if(!volgy.empty()&&index[volgy.top()] == index[i]) volgy.pop();
        volgy.push(i);
    }
    if (ans < 2) cout << -1;
    else cout << ans;
}
SubtaskSumTestVerdictTimeMemory
base100/100
1Accepted0/01ms500 KiB
2Accepted0/01ms508 KiB
3Accepted5/51ms316 KiB
4Accepted5/51ms316 KiB
5Accepted5/51ms384 KiB
6Accepted5/51ms316 KiB
7Accepted5/51ms316 KiB
8Accepted5/52ms536 KiB
9Accepted5/51ms316 KiB
10Accepted5/51ms400 KiB
11Accepted5/53ms316 KiB
12Accepted5/53ms344 KiB
13Accepted5/54ms508 KiB
14Accepted5/54ms444 KiB
15Accepted5/530ms564 KiB
16Accepted5/535ms564 KiB
17Accepted5/532ms1076 KiB
18Accepted5/532ms800 KiB
19Accepted5/534ms808 KiB
20Accepted5/537ms800 KiB
21Accepted5/537ms820 KiB
22Accepted5/537ms800 KiB