79522024-01-12 08:30:41adamSíkság (55)cpp17Time limit exceeded 28/55286ms4700 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++) {
        if(length - i - 1 <= found_length) break;
        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
base28/55
1Accepted0/03ms1824 KiB
2Accepted0/034ms2192 KiB
3Accepted2/23ms2228 KiB
4Accepted2/23ms2448 KiB
5Accepted2/23ms2804 KiB
6Accepted2/23ms2936 KiB
7Accepted3/33ms3028 KiB
8Accepted2/23ms3248 KiB
9Accepted3/33ms3468 KiB
10Accepted3/323ms3584 KiB
11Accepted3/34ms3896 KiB
12Accepted3/33ms3852 KiB
13Accepted3/316ms4700 KiB
14Time limit exceeded0/3250ms3624 KiB
15Time limit exceeded0/3254ms3752 KiB
16Time limit exceeded0/3268ms3784 KiB
17Time limit exceeded0/3286ms3852 KiB
18Time limit exceeded0/3257ms4112 KiB
19Time limit exceeded0/3252ms4044 KiB
20Time limit exceeded0/3273ms4212 KiB
21Time limit exceeded0/3246ms3736 KiB
22Time limit exceeded0/3266ms3816 KiB