79182024-01-12 00:39:52adamSíkság (55)cpp17Time limit exceeded 25/55280ms3956 KiB
#include <bits/stdc++.h>

using namespace std;

int main() {
    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/03ms1808 KiB
2Accepted0/032ms2224 KiB
3Accepted2/23ms2340 KiB
4Accepted2/23ms2556 KiB
5Accepted2/23ms2668 KiB
6Accepted2/23ms2752 KiB
7Accepted3/33ms2828 KiB
8Accepted2/23ms2828 KiB
9Accepted3/33ms2956 KiB
10Accepted3/326ms3076 KiB
11Accepted3/34ms3076 KiB
12Time limit exceeded0/3279ms3172 KiB
13Accepted3/335ms3956 KiB
14Time limit exceeded0/3261ms3032 KiB
15Time limit exceeded0/3240ms3256 KiB
16Time limit exceeded0/3273ms3488 KiB
17Time limit exceeded0/3280ms3588 KiB
18Time limit exceeded0/3240ms3492 KiB
19Time limit exceeded0/3248ms3656 KiB
20Time limit exceeded0/3277ms3704 KiB
21Time limit exceeded0/3243ms3832 KiB
22Time limit exceeded0/3266ms3888 KiB