18912022-12-07 12:03:29kicsiboglarSíkság (55)cpp11Wrong answer 42/5512ms4024 KiB
#include <iostream>
#include <vector>
#include <deque>

#define ll long long
using namespace std;

//ifstream cin ("input.in");
//ofstream cout ("output.out");

ll n,m,i,j,a,maxi=1,start,f,s,p,lastf,lasts;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    cin>>n;
    cin>>f;
    start=1;
    for (i=2;i<=n;++i)
    {
        cin>>a;
        if (a==f) lastf=i;
        else if (a==s) lasts=i;
        else 
        {
            if (!s)
            {
                if (abs(a-f)==1)
                {
                    s=a;
                    lasts=i;
                }
                else 
                {
                    f=a;
                    lastf=i;
                    start=i;
                }
            }
            else
            {
               if (abs(a-s)==1)
                {
                    f=s;
                    s=a;
                    start=lastf+1;
                    lastf=lasts;
                    lasts=i;
                }
                else 
                {
                    f=a;
                    lastf=i;
                    start=i;
                    s=0;
                    lasts=0;
                } 
            }
        }
        if (i-start+1>maxi)
        {
            maxi=i-start+1;
            p=start;
        }
    }
    cout<<maxi<<" "<<p;
}
SubtaskSumTestVerdictTimeMemory
base42/55
1Accepted0/03ms1888 KiB
2Wrong answer0/03ms2084 KiB
3Accepted2/22ms2432 KiB
4Wrong answer0/22ms2512 KiB
5Wrong answer0/22ms2716 KiB
6Accepted2/22ms2792 KiB
7Wrong answer0/32ms2788 KiB
8Accepted2/22ms2800 KiB
9Accepted3/32ms2920 KiB
10Accepted3/33ms3128 KiB
11Wrong answer0/33ms3248 KiB
12Accepted3/33ms3320 KiB
13Accepted3/312ms3384 KiB
14Wrong answer0/38ms3516 KiB
15Accepted3/39ms3612 KiB
16Accepted3/310ms3592 KiB
17Accepted3/312ms3588 KiB
18Accepted3/312ms3688 KiB
19Accepted3/312ms3720 KiB
20Accepted3/312ms3796 KiB
21Accepted3/37ms4020 KiB
22Accepted3/39ms4024 KiB