28662023-01-31 09:38:09zsebiSíkság (55)cpp11Wrong answer 42/5539ms5248 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
SubtaskSumTestVerdictTimeMemory
base42/55
1Accepted0/03ms1812 KiB
2Wrong answer0/04ms2020 KiB
3Wrong answer0/23ms2264 KiB
4Accepted2/22ms2388 KiB
5Wrong answer0/23ms2456 KiB
6Accepted2/23ms2664 KiB
7Accepted3/33ms3036 KiB
8Accepted2/23ms2992 KiB
9Accepted3/33ms3064 KiB
10Accepted3/36ms3068 KiB
11Accepted3/34ms3264 KiB
12Accepted3/34ms3400 KiB
13Wrong answer0/339ms5248 KiB
14Accepted3/319ms3708 KiB
15Accepted3/328ms3704 KiB
16Accepted3/335ms3828 KiB
17Accepted3/335ms3956 KiB
18Accepted3/337ms4208 KiB
19Accepted3/335ms3988 KiB
20Wrong answer0/337ms4120 KiB
21Wrong answer0/321ms4096 KiB
22Accepted3/328ms4088 KiB