89102024-02-04 13:31:50adamSíkság (55)cpp17Time limit exceeded 10/55300ms8136 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/0279ms2156 KiB
3Wrong answer0/23ms2364 KiB
4Accepted2/23ms2512 KiB
5Accepted2/23ms2576 KiB
6Time limit exceeded0/2298ms2676 KiB
7Accepted3/33ms2924 KiB
8Time limit exceeded0/2298ms3268 KiB
9Time limit exceeded0/3268ms3432 KiB
10Time limit exceeded0/3273ms2980 KiB
11Time limit exceeded0/3268ms3800 KiB
12Wrong answer0/34ms3908 KiB
13Time limit exceeded0/3300ms4076 KiB
14Accepted3/320ms5172 KiB
15Time limit exceeded0/3273ms4588 KiB
16Time limit exceeded0/3282ms5120 KiB
17Time limit exceeded0/3233ms5720 KiB
18Time limit exceeded0/3268ms6440 KiB
19Time limit exceeded0/3237ms6948 KiB
20Time limit exceeded0/3256ms7576 KiB
21Time limit exceeded0/3261ms7536 KiB
22Time limit exceeded0/3252ms8136 KiB