2866 2023. 01. 31 09:38:09 zsebi Síkság (55) cpp11 Hibás válasz 42/55 39ms 5248 KiB
// siksag.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <queue>
#include <map>
#include <algorithm>
#define ll long long 
using namespace std;
ll n, a,k;
deque<ll>v;
map<ll, ll>x;
ll melyik(ll a)
{
    if (abs(v[0] - a) == 1)return 1;
    else return 2;
}
ll has(ll a, ll b)
{
    if (x[a] < x[b])return 1;
    else return 2;
}
ll masik(ll a)
{
    if (abs(a- v[0])<=1)return 2;
    else return 1;
}
int main()
{

    cin >> n;
    ll maxi = 0,p;

  
    for (int i = 1; i <= n; ++i)
    {   
        cin >> a;
        x[a] = i;
        if (v.empty())
        {
            v.push_back(a);
            k = i;
        }
        else if (v.size() == 1)
        {
            if(abs(a - v[0]) == 1)
            v.push_back(a);
            else if(a!=v[0])
            {
                v[0] = i;
                k = i;
            }
        }
        else if (v.size()==2 && !count(v.begin(), v.end(), a))
        {
            if (abs(v[0] - a) != 1 && abs(v[1] - a) != 1)
            {
                v.clear();
                v.push_back(a);
                k = i;
            }
            else  if (has(v[0], v[1]) != melyik(a))
            {
                k = x[v[has(v[0], v[1])-1]] + 1;
                v[masik(a)-1] = a;
            }
            else
            {
                v.clear();
                v.push_back(a);
                k = i;
            }
        }
        if (i - k+1> maxi)
        {
            maxi = i - k+ 1;
            p = k;
        }

    }
    cout << maxi << " " << p;
    return 0;
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
Részfeladat Összpont Teszt Verdikt Idő Memória
base 42/55
1 Elfogadva 0/0 3ms 1812 KiB
2 Hibás válasz 0/0 4ms 2020 KiB
3 Hibás válasz 0/2 3ms 2264 KiB
4 Elfogadva 2/2 2ms 2388 KiB
5 Hibás válasz 0/2 3ms 2456 KiB
6 Elfogadva 2/2 3ms 2664 KiB
7 Elfogadva 3/3 3ms 3036 KiB
8 Elfogadva 2/2 3ms 2992 KiB
9 Elfogadva 3/3 3ms 3064 KiB
10 Elfogadva 3/3 6ms 3068 KiB
11 Elfogadva 3/3 4ms 3264 KiB
12 Elfogadva 3/3 4ms 3400 KiB
13 Hibás válasz 0/3 39ms 5248 KiB
14 Elfogadva 3/3 19ms 3708 KiB
15 Elfogadva 3/3 28ms 3704 KiB
16 Elfogadva 3/3 35ms 3828 KiB
17 Elfogadva 3/3 35ms 3956 KiB
18 Elfogadva 3/3 37ms 4208 KiB
19 Elfogadva 3/3 35ms 3988 KiB
20 Hibás válasz 0/3 37ms 4120 KiB
21 Hibás válasz 0/3 21ms 4096 KiB
22 Elfogadva 3/3 28ms 4088 KiB