50042023-04-08 23:57:23TomaSajtSíkság (55)cpp17Elfogadva 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;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base55/55
1Elfogadva0/03ms1876 KiB
2Elfogadva0/04ms2068 KiB
3Elfogadva2/23ms2280 KiB
4Elfogadva2/23ms2492 KiB
5Elfogadva2/23ms2704 KiB
6Elfogadva2/23ms2916 KiB
7Elfogadva3/33ms3004 KiB
8Elfogadva2/23ms3140 KiB
9Elfogadva3/33ms3340 KiB
10Elfogadva3/36ms3548 KiB
11Elfogadva3/34ms3560 KiB
12Elfogadva3/34ms3564 KiB
13Elfogadva3/332ms3560 KiB
14Elfogadva3/318ms3528 KiB
15Elfogadva3/326ms3528 KiB
16Elfogadva3/332ms3524 KiB
17Elfogadva3/335ms3520 KiB
18Elfogadva3/335ms3532 KiB
19Elfogadva3/335ms3660 KiB
20Elfogadva3/334ms3740 KiB
21Elfogadva3/318ms3992 KiB
22Elfogadva3/328ms3956 KiB