38082023-03-03 09:13:24hackemonSíkság (55)cpp17Wrong answer 16/5513ms6008 KiB
#include <bits/stdc++.h>
using namespace std;
//using namespace std::chrono;

#define pii pair<int,int>
#define pb push_back
#define vi vector<int>
#define vb vector<bool>
#define vl vector<ll>
#define vvi vector<vi>
#define vvb vector<vb>
#define vvl vector<vl>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define fScan {ios_base::sync_with_stdio(false); cin.tie(NULL);}
#define rep(i, a, b) for(int i = a; i < (b); i++)
#define REP(i, n) for(int i = 0;i <(n); i++)
using ll = long long;
using ld = long double;
ll mod = 1000000007;

const char ny =  '\n';

bool prime(ll a) {
    if (a==1) return 0;
    for (int i=2;i*i<=a;++i)
    {
        if (a%i==0) return 0;
    }
    return 1;
}

ll gcd(ll a,ll b) {
    if (b==0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a,ll b)
{
    return a/gcd(a,b)*b;
}

ll min(int a, ll b) {
    if(a< b) return a;
    else return b;
}


void solve() { 
    int n;
    cin >> n;
    vector<int> k(n);
    vector<int> halmazok, prefi;
    for(int i = 0;i < n;i++ ) cin >> k[i];
    
    halmazok.push_back(1);
    for(int i = 1;i< n;i++ ) {
        if(k[i] == k[i-1]) {
            halmazok[halmazok.size()-1]++;
        } else {
            halmazok.push_back(1);
        }
    }
    prefi.push_back(halmazok[0]-1);
    for(int i = 1;i< halmazok.size();i++ ) {
        prefi.push_back(prefi[prefi.size()-1] + halmazok[i]);
    }

    /*
    for(int i = 0;i< halmazok.size();i++ ) {
    cout << halmazok[i] << ' ';
    }
    cout << endl;
    for(int i = 0;i< prefi.size();i++ ) {
        cout << prefi[i] << ' ';
    }
    */

    vector<pair<int, int>> ansok;
    int index1 = 0, index2 = 0;
    ansok.push_back({1 , prefi[0]+1});

    for(int i = 1;i< halmazok.size();i++ ) {
        if(abs(k[index1] - k[prefi[i]]) < 2 ) {
            index2 = prefi[i];
        } else {
            ansok.push_back({index1+1, index2+1});
            //cout << index1 << ' ' << index2 << endl;
            if(abs(k[prefi[i]] - k[prefi[i-1]] < 2) && i > 1) {
                index1 = prefi[i-2]+1;
                index2 = prefi[i];
            } else {
                index1 = prefi[i-1]+1;
                index2 = prefi[i] + halmazok[i] - 1;
            }
        }
    }
    int ma = -1;
    int pos = 0;
    for(int i = 0;i< ansok.size();i++ ) {
        if(ansok[i].second - ansok[i].first > ma) {
            ma = ansok[i].second - ansok[i].first;
            pos = i;
        }
    }
    cout << ansok[pos].second - ansok[pos].first + 1<< ' ' << ansok[pos].first << endl;
    
    }


int main()
{
    fScan

    int t = 1;
    //comment out if necessary
    //cin>> t;


    //auto start = high_resolution_clock::now();
    while(t-- ) {
        solve();
    }
    //auto end = high_resolution_clock::now();
    //auto dur = duration_cast<milliseconds>(end-start);
    //cout<< "runtime: " << dur.count() << " milliseconds" << '\n';
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base16/55
1Accepted0/03ms1828 KiB
2Wrong answer0/04ms2276 KiB
3Wrong answer0/23ms2268 KiB
4Accepted2/22ms2372 KiB
5Wrong answer0/23ms2468 KiB
6Wrong answer0/22ms2680 KiB
7Wrong answer0/33ms2748 KiB
8Accepted2/23ms2764 KiB
9Wrong answer0/33ms2960 KiB
10Wrong answer0/33ms2924 KiB
11Wrong answer0/33ms2936 KiB
12Wrong answer0/33ms3232 KiB
13Wrong answer0/313ms4772 KiB
14Wrong answer0/39ms4212 KiB
15Wrong answer0/310ms4700 KiB
16Wrong answer0/312ms4468 KiB
17Accepted3/313ms4692 KiB
18Wrong answer0/313ms5448 KiB
19Accepted3/313ms6008 KiB
20Accepted3/313ms5760 KiB
21Accepted3/38ms5148 KiB
22Wrong answer0/39ms4960 KiB