79192024-01-12 00:42:36adamSíkság (55)cpp17Time limit exceeded 25/55300ms4348 KiB
#include <bits/stdc++.h>

using namespace std;

int main() {
    cin.tie(nullptr );
    ios_base::sync_with_stdio(false);
    int length = 0;
    cin >> length;
    vector<int> terrain(length, 0);
    for (int i = 0; i < length; i++) {
        cin >> terrain[i];
    }
    int found_index = -1;
    int found_length = 0;

    for (int i = 0; i < length; i++) {
        int a = i;
        int l = 0;
        int isLess = -1;
        while(abs(terrain[i] - terrain[a]) <= 1) {
            if (isLess == -1) {
                if (terrain[i] - terrain[a] == -1) isLess = 1;
                else if (terrain[i] - terrain[a] == 1) isLess = 0;
                a++;
                l++;
            } else {
                if (terrain[i] - terrain[a] == -1 && isLess == 1) {
                    a++;
                    l++;
                } else if (terrain[i] - terrain[a] == 1 && isLess == 0) {
                    a++;
                    l++;
                } else if (terrain[i] - terrain[a] == 0) {
                    a++;
                    l++;
                } else break;
            }
        }
        if(found_length < l) {
            found_index = i;
            found_length = l;
        }

    }
    cout << found_length << " " << found_index + 1;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base25/55
1Accepted0/03ms1860 KiB
2Accepted0/028ms2264 KiB
3Accepted2/23ms2336 KiB
4Accepted2/23ms2560 KiB
5Accepted2/23ms2756 KiB
6Accepted2/23ms2868 KiB
7Accepted3/33ms3092 KiB
8Accepted2/23ms3172 KiB
9Accepted3/33ms3296 KiB
10Accepted3/318ms3676 KiB
11Accepted3/34ms3636 KiB
12Time limit exceeded0/3241ms2792 KiB
13Accepted3/316ms4348 KiB
14Time limit exceeded0/3300ms3496 KiB
15Time limit exceeded0/3232ms3456 KiB
16Time limit exceeded0/3261ms3452 KiB
17Time limit exceeded0/3266ms3780 KiB
18Time limit exceeded0/3261ms3732 KiB
19Time limit exceeded0/3282ms3856 KiB
20Time limit exceeded0/3270ms3736 KiB
21Time limit exceeded0/3257ms3744 KiB
22Time limit exceeded0/3261ms3760 KiB