Submission #944636

#TimeUsernameProblemLanguageResultExecution timeMemory
944636wiiGap (APIO16_gap)C++17
30 / 100
997 ms46624 KiB
#include "gap.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int n, t;
vector<ll> num;
void dnc(ll l, ll r) {
    if (l > r)
        return;

    if (t == 1) {
        ll mn = -1, mx = -1;
        if (num.size() < n) MinMax(l, r, &mn, &mx);

        if (mn == -1) return;

        num.push_back(mn);
        num.push_back(mx);

        dnc(mn + 1, mx - 1);
        return;
    }

    ll mn = -1, mx = -1;
    for (int k = 1; k <= 60; ++k) {
        if (num.size() < n) MinMax(l, min(r, l + (1LL << k) - 1), &mn, &mx);
        if (mn != -1) {
            num.push_back(mn);
            if (mn != mx) num.push_back(mx);

            dnc(mn + 1, mx - 1);
            dnc(mx + 1, r - 1);
        }

        if (r <= l + (1LL << k) - 1)
            break;
    }
}

ll findGap(int T, int N) {
    n = N; t = T;
    dnc(0, 1e18);

    sort(num.begin(), num.end());

    ll res = 0;
    for (int i = 1; i < num.size(); ++i)
        res = max(res, num[i] - num[i - 1]);

	return res;
}

Compilation message (stderr)

gap.cpp: In function 'void dnc(ll, ll)':
gap.cpp:15:24: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   15 |         if (num.size() < n) MinMax(l, r, &mn, &mx);
      |             ~~~~~~~~~~~^~~
gap.cpp:28:24: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   28 |         if (num.size() < n) MinMax(l, min(r, l + (1LL << k) - 1), &mn, &mx);
      |             ~~~~~~~~~~~^~~
gap.cpp: In function 'll findGap(int, int)':
gap.cpp:49:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |     for (int i = 1; i < num.size(); ++i)
      |                     ~~^~~~~~~~~~~~
gap.cpp:49:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   49 |     for (int i = 1; i < num.size(); ++i)
      |     ^~~
gap.cpp:52:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   52 |  return res;
      |  ^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...