50032023-04-08 23:56:23TomaSajtSíkság (55)cpp17Wrong answer 53/5535ms4636 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  cin >> n;
  int prev, other = -1;
  cin >> prev;
  int start = 1;
  int consecutive_start = 1;
  int best_start = 0;
  int best_end = 0;
  for (int i = 2; i <= n; i++) {
    int curr;
    cin >> curr;
    if (curr == prev) {
    } else if (curr == other) {
      consecutive_start = i;
      swap(prev, other);
    } else if ((other == -1 && abs(curr - prev) == 1) ||
               (other != -1 && curr - prev == prev - other)) {
      start = consecutive_start;
      consecutive_start = i;
      other = prev;
      prev = curr;
    } else {
      start = i;
      consecutive_start = i;
      other = -1;
      prev = curr;
    }
    if (best_end - best_start < i - start) {
      best_end = i;
      best_start = start;
    }
  }
  cout << best_end - best_start + 1 << ' ' << best_start;
}
SubtaskSumTestVerdictTimeMemory
base53/55
1Accepted0/03ms1880 KiB
2Accepted0/04ms2124 KiB
3Accepted2/22ms2208 KiB
4Accepted2/23ms2392 KiB
5Wrong answer0/23ms2628 KiB
6Accepted2/23ms2680 KiB
7Accepted3/33ms2820 KiB
8Accepted2/23ms2948 KiB
9Accepted3/33ms3160 KiB
10Accepted3/34ms3340 KiB
11Accepted3/34ms3424 KiB
12Accepted3/34ms3664 KiB
13Accepted3/332ms3664 KiB
14Accepted3/319ms3768 KiB
15Accepted3/326ms3968 KiB
16Accepted3/332ms4080 KiB
17Accepted3/334ms4328 KiB
18Accepted3/335ms4260 KiB
19Accepted3/334ms4392 KiB
20Accepted3/334ms4500 KiB
21Accepted3/318ms4476 KiB
22Accepted3/328ms4636 KiB