Submission #832661

# Submission time Handle Problem Language Result Execution time Memory
832661 2023-08-21T13:13:19 Z erray Gap (APIO16_gap) C++17
100 / 100
39 ms 1176 KB
#include "gap.h"
#include <bits/stdc++.h>

using namespace std;

#ifdef DEBUG 
  #include "/home/eagle/ioi22/d2/debug.h"
#else 
  #define debug(...) void(37)
#endif

long long findGap(int T, int N) {
  debug(T, N);
  long long first = -1;
  long long last = -1;
  const long long inf = (long long) 1e18;
  MinMax(0, inf, &first, &last);
  long long ans = (last - first + N - 2) / (N - 1);
  if (N == 1) {
    return 0;
  } else if (T == 1) {
    long long L = first, R = last;
    for (int i = 0; i < (N - 1) / 2; ++i) {
      long long next_L = -1, next_R = -1;
      MinMax(L + 1, R - 1, &next_L, &next_R);
      ans = max({ans, next_L - L, R - next_R});
      L = next_L, R = next_R;
    }
    ans = max(ans, R - L);
  } else {
    long long cur = first;
    while (cur != last) {
      long long mn = -1, mx = -1;
      long long ask = -1;
      while (mn == -1) {
        ask = (ask == -1 ? ans : min(ask * 2, last - cur));
        MinMax(cur + 1, cur + ask, &mn, &mx);
        debug(mn, mx);
      }
      ans = max(ans, mn - cur);
      cur = mx;
    }
  }
  return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 0 ms 208 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 0 ms 208 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 7 ms 452 KB Output is correct
17 Correct 7 ms 472 KB Output is correct
18 Correct 9 ms 464 KB Output is correct
19 Correct 7 ms 464 KB Output is correct
20 Correct 6 ms 464 KB Output is correct
21 Correct 30 ms 1056 KB Output is correct
22 Correct 28 ms 1096 KB Output is correct
23 Correct 29 ms 1008 KB Output is correct
24 Correct 30 ms 984 KB Output is correct
25 Correct 33 ms 1088 KB Output is correct
26 Correct 35 ms 1056 KB Output is correct
27 Correct 30 ms 1176 KB Output is correct
28 Correct 29 ms 984 KB Output is correct
29 Correct 33 ms 956 KB Output is correct
30 Correct 25 ms 1084 KB Output is correct
31 Correct 0 ms 208 KB Output is correct
32 Correct 0 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 0 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 0 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
16 Correct 5 ms 512 KB Output is correct
17 Correct 5 ms 464 KB Output is correct
18 Correct 5 ms 464 KB Output is correct
19 Correct 5 ms 464 KB Output is correct
20 Correct 3 ms 464 KB Output is correct
21 Correct 17 ms 1056 KB Output is correct
22 Correct 18 ms 1064 KB Output is correct
23 Correct 19 ms 1104 KB Output is correct
24 Correct 23 ms 968 KB Output is correct
25 Correct 39 ms 976 KB Output is correct
26 Correct 19 ms 1052 KB Output is correct
27 Correct 19 ms 1080 KB Output is correct
28 Correct 19 ms 1084 KB Output is correct
29 Correct 21 ms 1044 KB Output is correct
30 Correct 10 ms 1104 KB Output is correct
31 Correct 1 ms 208 KB Output is correct
32 Correct 0 ms 208 KB Output is correct