76402024-01-10 10:20:21BenedekMartonSíkság (55)cpp14Wrong answer 43/5537ms6056 KiB
#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int t[n], m[100002], ln, lk, k=0, v=-1, maxh=0, maxi=0;
    for(int i=0; i<100002; i++)
    {
        m[i]=0;
    }
    for(int i=0; i<n; i++)
    {
        cin >> t[i];
    }
    ln=t[0];
    lk=t[0];
    while(v<n-1)
    {
        v++;
        m[t[v]]++;
        if(ln<t[v])
        {
            if(t[v]-lk>1)
            {
                if(v-k>maxh)
                {
                    maxh=v-k;
                    maxi=v;
                }
                for(k=k; m[lk]>0; k++)
                {
                    m[t[k]]--;
                }
                if(m[t[v]-1]>0)
                {
                    lk=t[v]-1;
                }
                else
                {
                    lk=t[v];
                }
                ln=t[v];
            }
            else
            {
                ln=t[v];
            }
        }
        else if(lk>t[v])
        {
            if(ln-t[v]>1)
            {
                if(v-k>maxh)
                {
                    maxh=v-k;
                    maxi=v;
                }
                for(k=k; m[ln]>0; k++)
                {
                    m[t[k]]--;
                }
                if(m[t[v]+1]>0)
                {
                    ln=t[v]+1;
                }
                else
                {
                    ln=t[v];
                }
                lk=t[v];
            }
            else
            {
                lk=t[v];
            }
        }
        //cout << k+1 << " " << v+1 << endl;
    }
    if(v-k+1>maxh)
    {
        maxh=v-k+1;
        maxi=v+1;
    }
    cout << maxh << " " << maxi-maxh+1;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base43/55
1Accepted0/03ms2648 KiB
2Accepted0/06ms3200 KiB
3Accepted2/23ms3296 KiB
4Accepted2/23ms3512 KiB
5Accepted2/23ms3724 KiB
6Accepted2/23ms3812 KiB
7Accepted3/33ms3808 KiB
8Accepted2/23ms3732 KiB
9Accepted3/33ms3816 KiB
10Accepted3/36ms4140 KiB
11Accepted3/34ms4340 KiB
12Accepted3/34ms4452 KiB
13Wrong answer0/335ms5268 KiB
14Accepted3/320ms5512 KiB
15Accepted3/328ms5524 KiB
16Accepted3/335ms5656 KiB
17Accepted3/337ms5736 KiB
18Wrong answer0/337ms5968 KiB
19Wrong answer0/335ms5940 KiB
20Wrong answer0/335ms6056 KiB
21Accepted3/319ms5464 KiB
22Accepted3/328ms5740 KiB