89122024-02-04 13:49:40adamSíkság (55)cpp17Time limit exceeded 10/55300ms3528 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 current_longest_length = 0;
    int current_longest_index = 0;
    int plain_length = 0;
    pair<int, int> possible(-1, -1);
    int first_other_index = 0; // this stores
    for (int i = 0; i < length; i++) {
        if (plain_length == 0) {
            plain_length++;
            possible.first = terrain[i];
            continue;
        } else if (possible.second == -1 && terrain[i] != possible.first && abs(terrain[i] - possible.first) <= 1) {
            first_other_index = i;
            possible.second = terrain[i];
            plain_length++;
            continue;
        } else if (terrain[i] == possible.first || terrain[i] == possible.second) {
            plain_length++;
            continue;
        } else {
            if (current_longest_length < plain_length) {
                current_longest_length = plain_length;
                current_longest_index = i - plain_length;
            }
            possible = pair(-1, -1);
            if (plain_length > 1) {
                i = first_other_index-1;
            }
            plain_length = 0;
        }
    }
    cout << current_longest_length << " " << current_longest_index + 1 << endl;

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base10/55
1Accepted0/03ms1812 KiB
2Time limit exceeded0/0282ms2060 KiB
3Wrong answer0/23ms2244 KiB
4Accepted2/23ms2292 KiB
5Accepted2/23ms2544 KiB
6Time limit exceeded0/2300ms2604 KiB
7Accepted3/33ms2700 KiB
8Time limit exceeded0/2300ms2588 KiB
9Time limit exceeded0/3261ms2588 KiB
10Time limit exceeded0/3275ms2896 KiB
11Time limit exceeded0/3252ms2740 KiB
12Wrong answer0/34ms2660 KiB
13Time limit exceeded0/3300ms2516 KiB
14Accepted3/320ms3528 KiB
15Time limit exceeded0/3257ms2348 KiB
16Time limit exceeded0/3280ms2300 KiB
17Time limit exceeded0/3264ms2600 KiB
18Time limit exceeded0/3252ms2688 KiB
19Time limit exceeded0/3273ms2652 KiB
20Time limit exceeded0/3266ms2948 KiB
21Time limit exceeded0/3264ms2632 KiB
22Time limit exceeded0/3233ms3132 KiB