Submission #1015230

# Submission time Handle Problem Language Result Execution time Memory
1015230 2024-07-06T07:42:02 Z vjudge1 Gap (APIO16_gap) C++17
46.8129 / 100
45 ms 6868 KB
#include <bits/stdc++.h>
// #include "grader.cpp"
#include "gap.h"

using namespace std;

typedef long long ll;
ll n;
set<ll> st;
void recur(ll l, ll r){
    if (r < l or st.size() == n) return ;
    if (r - l <= 1){
        MinMax(l, r, &l, &r);
        if (l != -1){
            st.insert(l);
            st.insert(r);
        }
        return ;
    }

    ll mid = (l + r) / 2;
    
    ll mn, mx;
    MinMax(l, mid, &mn, &mx);

    if (mn != -1){
        st.insert(mn);
        st.insert(mx);
        recur(mn + 1, mx - 1);
    }

    MinMax(mid + 1, r, &mn, &mx);
    if (mn != -1){
        st.insert(mn);
        st.insert(mx);
        recur(mn + 1, mx - 1);
    }
}

ll findGap(int T, int N){
    n = N;
    ll res;
    if (T == 1 or N <= 8){
        ll mn = 0, mx = 1e18;
        while (N > 0){
            N -= 2;

            MinMax(mn, mx, &mn, &mx);

            st.insert(mn);
            st.insert(mx);
            
            mn++;
            mx--;
        }

        vector<ll> vec;
        for (ll x : st)
            vec.push_back(x);

        ll res = 0;
        for (ll i = 1; i < vec.size(); i ++)
            res = max(res, vec[i] - vec[i - 1]);
        return res;
    }
    else if (N <= 200){
        recur(0, 1e18);
        vector<ll> vec;
        for (ll x : st)
            vec.push_back(x);

        ll res = 0;
        for (ll i = 1; i < vec.size(); i ++)
            res = max(res, vec[i] - vec[i - 1]);
        return res;
    }
    else{
        ll l = 0, r = 1e18;
        ll mn, mx;
        MinMax(l, r, &mn, &mx);

        ll first = mn, last = mx;

        ll ans = 1;
        ll actual = 1;
        l = mn + 1;

        while (l <= last){
            r = l + ans;
            MinMax(l, r, &mn, &mx);

            if (mn == -1)
                ans *= 2;
            else{
                actual = max(actual, mn - (l - 1));
                ans = actual;
                l = mx + 1;
            }
        }

        return actual;
    }
}

Compilation message

gap.cpp: In function 'void recur(ll, ll)':
gap.cpp:11:28: warning: comparison of integer expressions of different signedness: 'std::set<long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   11 |     if (r < l or st.size() == n) return ;
      |                  ~~~~~~~~~~^~~~
gap.cpp: In function 'll findGap(int, int)':
gap.cpp:62:26: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |         for (ll i = 1; i < vec.size(); i ++)
      |                        ~~^~~~~~~~~~~~
gap.cpp:73:26: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |         for (ll i = 1; i < vec.size(); i ++)
      |                        ~~^~~~~~~~~~~~
gap.cpp:82:12: warning: unused variable 'first' [-Wunused-variable]
   82 |         ll first = mn, last = mx;
      |            ^~~~~
gap.cpp:42:8: warning: unused variable 'res' [-Wunused-variable]
   42 |     ll res;
      |        ^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 9 ms 2096 KB Output is correct
17 Correct 9 ms 2136 KB Output is correct
18 Correct 9 ms 2136 KB Output is correct
19 Correct 10 ms 2136 KB Output is correct
20 Correct 8 ms 2136 KB Output is correct
21 Correct 40 ms 6868 KB Output is correct
22 Correct 45 ms 6860 KB Output is correct
23 Correct 40 ms 6868 KB Output is correct
24 Correct 44 ms 6868 KB Output is correct
25 Correct 38 ms 6864 KB Output is correct
26 Correct 41 ms 6860 KB Output is correct
27 Correct 38 ms 6860 KB Output is correct
28 Correct 40 ms 6860 KB Output is correct
29 Correct 42 ms 6868 KB Output is correct
30 Correct 35 ms 6868 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 3 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Partially correct 0 ms 344 KB Partially correct
6 Partially correct 0 ms 344 KB Partially correct
7 Partially correct 0 ms 344 KB Partially correct
8 Partially correct 0 ms 344 KB Partially correct
9 Partially correct 0 ms 344 KB Partially correct
10 Partially correct 0 ms 344 KB Partially correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Partially correct 0 ms 344 KB Partially correct
16 Correct 4 ms 600 KB Output is correct
17 Correct 4 ms 648 KB Output is correct
18 Correct 5 ms 600 KB Output is correct
19 Correct 7 ms 600 KB Output is correct
20 Correct 3 ms 600 KB Output is correct
21 Correct 25 ms 1056 KB Output is correct
22 Correct 16 ms 1112 KB Output is correct
23 Correct 16 ms 1112 KB Output is correct
24 Correct 16 ms 1112 KB Output is correct
25 Partially correct 32 ms 1112 KB Partially correct
26 Correct 15 ms 1112 KB Output is correct
27 Correct 17 ms 1232 KB Output is correct
28 Correct 17 ms 1112 KB Output is correct
29 Correct 21 ms 1112 KB Output is correct
30 Correct 17 ms 1112 KB Output is correct
31 Partially correct 0 ms 344 KB Partially correct
32 Partially correct 0 ms 344 KB Partially correct