89112024-02-04 13:48:34adamSíkság (55)cpp17Wrong answer 0/55300ms4292 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++) {
        if (i == 1000) {
            cout << "kys";
        }
        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 << i << endl;
    }
    cout << current_longest_length << " " << current_longest_index + 1 << endl;

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/55
1Wrong answer0/03ms1816 KiB
2Time limit exceeded0/0300ms1400 KiB
3Wrong answer0/23ms2440 KiB
4Wrong answer0/23ms2480 KiB
5Wrong answer0/23ms2696 KiB
6Time limit exceeded0/2300ms2824 KiB
7Wrong answer0/33ms3064 KiB
8Time limit exceeded0/2298ms3260 KiB
9Time limit exceeded0/3268ms2624 KiB
10Time limit exceeded0/3264ms3524 KiB
11Time limit exceeded0/3252ms3580 KiB
12Wrong answer0/34ms3644 KiB
13Time limit exceeded0/3300ms3440 KiB
14Wrong answer0/320ms4292 KiB
15Time limit exceeded0/3300ms3192 KiB
16Time limit exceeded0/3261ms3196 KiB
17Time limit exceeded0/3261ms3372 KiB
18Time limit exceeded0/3273ms3596 KiB
19Time limit exceeded0/3268ms3568 KiB
20Time limit exceeded0/3268ms3676 KiB
21Time limit exceeded0/3229ms3380 KiB
22Time limit exceeded0/3245ms3528 KiB