37262023-03-02 14:28:03AGergoSíkság (55)cpp14Wrong answer 3/55300ms5156 KiB
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int meresSzam;
    cin >> meresSzam;

    vector<int> szamok(meresSzam+1,-2);

    for(int i = 0; i < meresSzam; i++)
    {
        cin >> szamok[i];

    }

    int longest = 0;
    int len = 0;
    bool lower = false;
    bool higher = false;

    int j;
    int start;

    for(int i = 0; i < meresSzam+1;i++) //i - start pos
    {
        len = 0;
        j = i+1;

        while(!lower && !higher)
        {
            if(szamok[i+1] == szamok[i]-1)
            {
                lower = true;
            }
            else if( szamok[i+1] == szamok[i] +1)
            {
                higher = true;
            }
            else if(szamok[i+1] == szamok[i])
            {
                i++;
                len++;
            }
            else
            {
                len = 0;
                break;
            }
        }

        while(lower)
        {
            if(szamok[j] != szamok[i] && szamok[j] != szamok[i]-1)
            {
                lower = false;
                break;
            }

            j++;
            len++;
        }
        while(higher)
        {
            if(szamok[j] != szamok[i] && szamok[j] != szamok[i]+1)
            {
                higher = false;
                break;
            }

            j++;
            len++;
        }

        //cout << i << "-" << len << "\n";

        if(len > longest)
        {
            longest = len;
            start = i;
        }

    }

    cout << longest << " " << start;

}
SubtaskSumTestVerdictTimeMemory
base3/55
1Accepted0/03ms1808 KiB
2Wrong answer0/012ms2168 KiB
3Wrong answer0/22ms2112 KiB
4Wrong answer0/23ms2312 KiB
5Wrong answer0/22ms2564 KiB
6Wrong answer0/23ms3036 KiB
7Wrong answer0/33ms3088 KiB
8Wrong answer0/23ms3176 KiB
9Wrong answer0/33ms3308 KiB
10Wrong answer0/312ms3708 KiB
11Wrong answer0/34ms4028 KiB
12Accepted3/3167ms4008 KiB
13Wrong answer0/332ms4636 KiB
14Wrong answer0/319ms4636 KiB
15Time limit exceeded0/3300ms3520 KiB
16Wrong answer0/379ms4716 KiB
17Time limit exceeded0/3250ms4936 KiB
18Wrong answer0/335ms5156 KiB
19Time limit exceeded0/3252ms3996 KiB
20Time limit exceeded0/3282ms4000 KiB
21Time limit exceeded0/3212ms4656 KiB
22Time limit exceeded0/3266ms4188 KiB