50032023-04-08 23:56:23TomaSajtSíkság (55)cpp17Hibás válasz 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;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base53/55
1Elfogadva0/03ms1880 KiB
2Elfogadva0/04ms2124 KiB
3Elfogadva2/22ms2208 KiB
4Elfogadva2/23ms2392 KiB
5Hibás válasz0/23ms2628 KiB
6Elfogadva2/23ms2680 KiB
7Elfogadva3/33ms2820 KiB
8Elfogadva2/23ms2948 KiB
9Elfogadva3/33ms3160 KiB
10Elfogadva3/34ms3340 KiB
11Elfogadva3/34ms3424 KiB
12Elfogadva3/34ms3664 KiB
13Elfogadva3/332ms3664 KiB
14Elfogadva3/319ms3768 KiB
15Elfogadva3/326ms3968 KiB
16Elfogadva3/332ms4080 KiB
17Elfogadva3/334ms4328 KiB
18Elfogadva3/335ms4260 KiB
19Elfogadva3/334ms4392 KiB
20Elfogadva3/334ms4500 KiB
21Elfogadva3/318ms4476 KiB
22Elfogadva3/328ms4636 KiB