37632023-03-02 20:55:31rennVölgy (100 pont)cpp17Wrong answer 55/10014ms5612 KiB
#include <bits/stdc++.h>
using namespace std;

#define GOTTAGOFAST cin.tie(0); ios::sync_with_stdio(0);
typedef pair<int,int> pii;

int main() {

    GOTTAGOFAST

    int n;
    cin >> n;

    int prev = -1, curr, next;
    cin >> curr;

    vector<pair<int, pii>> csucsok, kovcsucsok;

    for(int i = 1; i < n; i++)
    {
        cin >> next;
        if(curr > prev && curr > next)
            csucsok.push_back({curr, {i, 0}});

        if(curr == prev && curr > next)
            csucsok.push_back({curr, {i, 1}});

        if(curr > prev && curr == next)
            csucsok.push_back({curr, {i, 2}});

        prev = curr;
        curr = next;
    }
    next = -1;
    if(curr > prev && curr > next)
        csucsok.push_back({curr, {n, 0}});

    if(curr == prev && curr > next)
        csucsok.push_back({curr, {n, 1}});

    if(curr > prev && curr == next)
        csucsok.push_back({curr, {n, 2}});

    if(csucsok.size() < 2)
    {
        cout << "0\n";
        return 0;
    }

    if(csucsok.size() == 2)
    {
        cout << csucsok[1].second.first-csucsok[0].second.first << "\n";
        return 0;
    }

    int maxl = -1;
    while(1) {
        kovcsucsok.push_back(csucsok[0]);

        for (int i = 1, j = csucsok.size() - 1; i < j; i++) {
            if (!(csucsok[i].first < csucsok[i - 1].first && csucsok[i].first < csucsok[i + 1].first)) {
                kovcsucsok.push_back(csucsok[i]);
            }
        }

        kovcsucsok.push_back(csucsok[csucsok.size() - 1]);
        if(csucsok.size() == kovcsucsok.size())
            break;

        csucsok = kovcsucsok;
        kovcsucsok.clear();
    }

    for(int i = 1; i < csucsok.size(); i++)
    {
        if(csucsok[i-1].second.second == 2 || csucsok[i].second.second == 1)
            continue;

        maxl = max(csucsok[i].second.first-csucsok[i-1].second.first, maxl);
    }

    cout << maxl << "\n";

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base55/100
1Accepted0/03ms1828 KiB
2Accepted0/03ms2068 KiB
3Accepted5/52ms2240 KiB
4Accepted5/53ms2448 KiB
5Accepted5/52ms2676 KiB
6Accepted5/53ms2884 KiB
7Wrong answer0/53ms3380 KiB
8Accepted5/53ms3452 KiB
9Wrong answer0/53ms3416 KiB
10Accepted5/53ms3800 KiB
11Accepted5/53ms3688 KiB
12Wrong answer0/53ms3880 KiB
13Wrong answer0/54ms3964 KiB
14Accepted5/54ms3968 KiB
15Wrong answer0/514ms5612 KiB
16Wrong answer0/514ms5576 KiB
17Wrong answer0/512ms3504 KiB
18Accepted5/512ms3596 KiB
19Accepted5/512ms3728 KiB
20Accepted5/513ms3832 KiB
21Wrong answer0/513ms3768 KiB
22Wrong answer0/513ms3864 KiB