50042023-04-08 23:57:23TomaSajtSíkság (55)cpp17Accepted 55/5535ms3992 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 = 1;
  int best_end = 1;
  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
base55/55
1Accepted0/03ms1876 KiB
2Accepted0/04ms2068 KiB
3Accepted2/23ms2280 KiB
4Accepted2/23ms2492 KiB
5Accepted2/23ms2704 KiB
6Accepted2/23ms2916 KiB
7Accepted3/33ms3004 KiB
8Accepted2/23ms3140 KiB
9Accepted3/33ms3340 KiB
10Accepted3/36ms3548 KiB
11Accepted3/34ms3560 KiB
12Accepted3/34ms3564 KiB
13Accepted3/332ms3560 KiB
14Accepted3/318ms3528 KiB
15Accepted3/326ms3528 KiB
16Accepted3/332ms3524 KiB
17Accepted3/335ms3520 KiB
18Accepted3/335ms3532 KiB
19Accepted3/335ms3660 KiB
20Accepted3/334ms3740 KiB
21Accepted3/318ms3992 KiB
22Accepted3/328ms3956 KiB