18762022-12-06 21:02:09kovacs.peter.18fSíkság (55)cpp11Elfogadva 55/5516ms4656 KiB
#include <iostream>
#include <vector>
#include <map>

using namespace std;

int main() {
    cin.sync_with_stdio(false);
    cin.tie(nullptr);

    int N;
    cin >> N;
    vector<int> heightS(N);
    map<int, int> countS;
    int different = 0, max_begin = 0, max_end = 0;
    for (int l = 0, r = 0; r < N; r++) { // zárt intervallum
        cin >> heightS[r];
        if (++countS[heightS[r]] == 1) {
            ++different;
        }
        while (different == 3) {
            if (--countS[heightS[l]] == 0) {
                --different;
                countS.erase(heightS[l]);
            }
            ++l;
        }
        if (abs(countS.begin()->first - countS.rbegin()->first) != 1) {
            while (different == 2) {
                if (--countS[heightS[l]] == 0) {
                    --different;
                    countS.erase(heightS[l]);
                }
                ++l;
            }
        }
        if (r - l > max_end - max_begin) {
            max_begin = l;
            max_end = r;
        }
    }
    cout << max_end - max_begin + 1 << " " << max_begin + 1 << '\n';
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base55/55
1Elfogadva0/03ms1824 KiB
2Elfogadva0/03ms2236 KiB
3Elfogadva2/22ms2264 KiB
4Elfogadva2/22ms2432 KiB
5Elfogadva2/22ms2632 KiB
6Elfogadva2/22ms2704 KiB
7Elfogadva3/32ms2940 KiB
8Elfogadva2/22ms3048 KiB
9Elfogadva3/32ms3252 KiB
10Elfogadva3/33ms3360 KiB
11Elfogadva3/33ms3364 KiB
12Elfogadva3/33ms3364 KiB
13Elfogadva3/314ms4008 KiB
14Elfogadva3/310ms4136 KiB
15Elfogadva3/313ms4340 KiB
16Elfogadva3/314ms4460 KiB
17Elfogadva3/314ms4536 KiB
18Elfogadva3/316ms4616 KiB
19Elfogadva3/314ms4544 KiB
20Elfogadva3/314ms4500 KiB
21Elfogadva3/38ms4320 KiB
22Elfogadva3/310ms4656 KiB