Submission #1107484

# Submission time Handle Problem Language Result Execution time Memory
1107484 2024-11-01T09:37:29 Z evenvalue Gap (APIO16_gap) C++17
100 / 100
43 ms 5820 KB
#include "gap.h"
#include <bits/stdc++.h>
using namespace std;

template<typename T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template<typename T>
using max_heap = priority_queue<T, vector<T>, less<T>>;

#define int long long

constexpr int kInf = 1e18;
constexpr int kMod = 1e9 + 7;

pair<int, int> ask(const int l, const int r) {
  int mn, mx;
  MinMax(l, r, &mn, &mx);
  return {mn, mx};
}

int subtask1(const int n) {
  vector<int> l, r;

  int a = 0, b = kInf;
  while (l.size() + r.size() < n) {
    const auto [x, y] = ask(a, b);
    l.push_back(x);
    r.push_back(y);
    a = x + 1, b = y - 1;
  }

  for (int i = r.size() - 1; i >= 0; i--) {
    l.push_back(r[i]);
  }

  int ans = 0;
  for (int i = 1; i < l.size(); i++) {
    ans = max(ans, l[i] - l[i - 1]);
  }

  return ans;
}

int subtask2(const int n) {
  auto [l, r] = ask(0, kInf);
  if (r - l + 1 == n) return 1;

  const int each = (r - l - 1) / (n - 1);
  const int extra = (r - l - 1) % (n - 1);

  int last = l;
  vector<int> elems = {l};
  for (int i = 1; i <= n - 1; i++) {
    const int len = each + (i <= extra);
    const int a = last + 1;
    const int b = a + len - 1;
    const auto [x, y] = ask(a, b);
    if (x != -1) elems.push_back(x);
    if (y != -1) elems.push_back(y);
    last = b;
  }

  elems.push_back(r);

  int ans = 0;
  for (int i = 1; i < elems.size(); i++) {
    ans = max(ans, elems[i] - elems[i - 1]);
  }

  return ans;
}

int findGap(int32_t T, int32_t n) {
  if (T == 1) return subtask1(n);
  if (T == 2) return subtask2(n);
  assert(false);
}

Compilation message

gap.cpp: In function 'long long int subtask1(long long int)':
gap.cpp:25:30: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'const long long int' [-Wsign-compare]
   25 |   while (l.size() + r.size() < n) {
      |          ~~~~~~~~~~~~~~~~~~~~^~~
gap.cpp:37:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |   for (int i = 1; i < l.size(); i++) {
      |                   ~~^~~~~~~~~~
gap.cpp: In function 'long long int subtask2(long long int)':
gap.cpp:66:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |   for (int i = 1; i < elems.size(); i++) {
      |                   ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 2552 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 1 ms 2384 KB Output is correct
10 Correct 1 ms 2384 KB Output is correct
11 Correct 1 ms 2384 KB Output is correct
12 Correct 1 ms 2384 KB Output is correct
13 Correct 1 ms 2384 KB Output is correct
14 Correct 1 ms 2384 KB Output is correct
15 Correct 1 ms 2384 KB Output is correct
16 Correct 10 ms 2896 KB Output is correct
17 Correct 9 ms 2896 KB Output is correct
18 Correct 8 ms 2896 KB Output is correct
19 Correct 10 ms 3068 KB Output is correct
20 Correct 7 ms 2896 KB Output is correct
21 Correct 27 ms 4212 KB Output is correct
22 Correct 28 ms 4224 KB Output is correct
23 Correct 30 ms 4208 KB Output is correct
24 Correct 29 ms 4360 KB Output is correct
25 Correct 25 ms 4212 KB Output is correct
26 Correct 32 ms 4204 KB Output is correct
27 Correct 28 ms 4204 KB Output is correct
28 Correct 27 ms 4192 KB Output is correct
29 Correct 27 ms 4204 KB Output is correct
30 Correct 22 ms 4212 KB Output is correct
31 Correct 1 ms 2384 KB Output is correct
32 Correct 1 ms 2384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 1 ms 2384 KB Output is correct
10 Correct 1 ms 2384 KB Output is correct
11 Correct 1 ms 2384 KB Output is correct
12 Correct 1 ms 2384 KB Output is correct
13 Correct 2 ms 2384 KB Output is correct
14 Correct 1 ms 2384 KB Output is correct
15 Correct 2 ms 2384 KB Output is correct
16 Correct 9 ms 2896 KB Output is correct
17 Correct 10 ms 2896 KB Output is correct
18 Correct 12 ms 2968 KB Output is correct
19 Correct 9 ms 2896 KB Output is correct
20 Correct 5 ms 2384 KB Output is correct
21 Correct 36 ms 3896 KB Output is correct
22 Correct 37 ms 3928 KB Output is correct
23 Correct 36 ms 3776 KB Output is correct
24 Correct 37 ms 4044 KB Output is correct
25 Correct 34 ms 5820 KB Output is correct
26 Correct 43 ms 3976 KB Output is correct
27 Correct 42 ms 3784 KB Output is correct
28 Correct 40 ms 3944 KB Output is correct
29 Correct 36 ms 3960 KB Output is correct
30 Correct 25 ms 3144 KB Output is correct
31 Correct 1 ms 2384 KB Output is correct
32 Correct 1 ms 2384 KB Output is correct