Submission #950921

# Submission time Handle Problem Language Result Execution time Memory
950921 2024-03-21T02:15:38 Z kilkuwu Gap (APIO16_gap) C++17
30 / 100
39 ms 3788 KB
#include <bits/stdc++.h>

#ifndef LOCAL
#include "gap.h"
#else

void MinMax(long long, long long, long long*, long long*);

static void my_assert(int k){ if (!k) exit(1); }


long long findGap(int, int);

static int subtask_num, __N;
static long long A[100001];
static long long call_count;
void MinMax(long long s, long long t, long long *mn, long long *mx) {
  int lo = 1, hi = __N, left = __N+1, right = 0;
  my_assert(s <= t && mn != NULL && mx != NULL);
  while (lo <= hi){
    int mid = (lo+hi)>>1;
    if (A[mid] >= s) hi = mid - 1, left = mid;
    else lo = mid + 1;
  }
  lo = 1, hi = __N;
  while (lo <= hi){
    int mid = (lo+hi)>>1;
    if (A[mid] <= t) lo = mid + 1, right = mid;
    else hi = mid - 1;
  }
  if (left > right) *mn = *mx = -1;
  else{
    *mn = A[left];
    *mx = A[right];
  }
  if (subtask_num == 1) call_count++;
  else if (subtask_num == 2) call_count += right-left+2;
}

int main()
{
  FILE *in = stdin, *out = stdout;
  my_assert(2 == fscanf(in, "%d%d", &subtask_num, &__N));
  my_assert(1 <= subtask_num && subtask_num <= 2);
  my_assert(2 <= __N && __N <= 100000);
  for (int i=1;i<=__N;i++) my_assert(1 == fscanf(in, "%lld", A+i));
  for (int i=1;i<__N;i++) my_assert(A[i] < A[i+1]);
  fprintf(out, "%lld\n", findGap(subtask_num, __N));
  fprintf(out, "%lld\n", call_count);
}
#endif
#ifdef LOCAL
#include "template\debug.hpp"
#else
#define dbg(...) ;
#define timer(...) ;
#endif

struct Subtask1 {
  int n;

  Subtask1(int _n) : n(_n) {}

  long long solve() {
    std::vector<long long> a(n);

    MinMax(0, 1e18, &a[0], &a.back());

    for (int i = 1; i <= n - i - 1; i++) {
      MinMax(a[i - 1] + 1, a[n - i] - 1, &a[i], &a[n - i - 1]);
    }

    long long ans = a[1] - a[0];
    for (int i = 1; i + 1 < n; i++) {
      ans = std::max(ans, a[i + 1] - a[i]);
    }
    return ans;
  }
};


struct Subtask2 {
  int n;

  Subtask2(int _n) : n(_n) {}

  long long solve() {
    long long lo, hi;
    MinMax(0, 1e18, &lo, &hi);
    dbg(lo, hi);

    // we can do this 
  
    long long gap = (hi - lo - 1) / (n - 1);
    if (gap * (n - 1) < (hi - lo - 1)) gap++;
    dbg(gap);

    // we can do that now 
    long long ans = 0;
    
    for (int i = 0; i < n - 1; i++) {
      long long ff = lo + 1 + gap * i;
      long long ee = lo + gap * (i + 1);
      ee = std::min(ee, hi - 1);
      dbg(ff, ee);

      long long r1, r2;
      MinMax(ff, ee, &r1, &r2);
      ans = std::max(ans, r2 - r1);
      if (i == 0) {
        ans = std::max(ans, r1 - lo);
      } 
      if (i == n - 2) {
        ans = std::max(ans, hi - r2);
      }
    }
    return ans;
  }
};

long long findGap(int T, int N) {
  dbg("called ", T, N);
  if (T == 1) {
    Subtask1 sub1(N);
    return sub1.solve();
  } else {
    Subtask2 sub2(N);
    return sub2.solve();
  }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2472 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 1 ms 2548 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2488 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 8 ms 2584 KB Output is correct
17 Correct 10 ms 2576 KB Output is correct
18 Correct 8 ms 2584 KB Output is correct
19 Correct 8 ms 2656 KB Output is correct
20 Correct 6 ms 2572 KB Output is correct
21 Correct 28 ms 3760 KB Output is correct
22 Correct 29 ms 3636 KB Output is correct
23 Correct 28 ms 3624 KB Output is correct
24 Correct 28 ms 3616 KB Output is correct
25 Correct 25 ms 3616 KB Output is correct
26 Correct 28 ms 3788 KB Output is correct
27 Correct 29 ms 3536 KB Output is correct
28 Correct 28 ms 3632 KB Output is correct
29 Correct 34 ms 3604 KB Output is correct
30 Correct 24 ms 3600 KB Output is correct
31 Correct 0 ms 2392 KB Output is correct
32 Correct 1 ms 2392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 2392 KB Output isn't correct
2 Incorrect 0 ms 2392 KB Output isn't correct
3 Incorrect 1 ms 2392 KB Output isn't correct
4 Incorrect 1 ms 2392 KB Output isn't correct
5 Incorrect 1 ms 2392 KB Output isn't correct
6 Incorrect 1 ms 2392 KB Output isn't correct
7 Incorrect 1 ms 2392 KB Output isn't correct
8 Incorrect 1 ms 2392 KB Output isn't correct
9 Incorrect 1 ms 2392 KB Output isn't correct
10 Incorrect 1 ms 2392 KB Output isn't correct
11 Incorrect 1 ms 2392 KB Output isn't correct
12 Incorrect 1 ms 2392 KB Output isn't correct
13 Incorrect 1 ms 2392 KB Output isn't correct
14 Incorrect 1 ms 2392 KB Output isn't correct
15 Incorrect 1 ms 2392 KB Output isn't correct
16 Incorrect 9 ms 2752 KB Output isn't correct
17 Incorrect 11 ms 2584 KB Output isn't correct
18 Incorrect 11 ms 2836 KB Output isn't correct
19 Incorrect 10 ms 2576 KB Output isn't correct
20 Runtime error 5 ms 2740 KB Execution failed because the return code was nonzero
21 Incorrect 39 ms 3020 KB Output isn't correct
22 Incorrect 38 ms 2860 KB Output isn't correct
23 Incorrect 38 ms 2864 KB Output isn't correct
24 Incorrect 38 ms 2856 KB Output isn't correct
25 Incorrect 38 ms 2848 KB Output isn't correct
26 Incorrect 38 ms 2856 KB Output isn't correct
27 Incorrect 38 ms 2856 KB Output isn't correct
28 Incorrect 38 ms 2856 KB Output isn't correct
29 Incorrect 38 ms 3024 KB Output isn't correct
30 Runtime error 22 ms 2856 KB Execution failed because the return code was nonzero
31 Incorrect 1 ms 2392 KB Output isn't correct
32 Incorrect 1 ms 2392 KB Output isn't correct