Submission #282637

# Submission time Handle Problem Language Result Execution time Memory
282637 2020-08-24T16:29:27 Z AaronNaidu Gap (APIO16_gap) C++14
43.0082 / 100
108 ms 6260 KB
#include <bits/stdc++.h>
#include "gap.h"
using namespace std;
typedef long long ll;

ll mn = 0;
ll mx = 0;
ll n;
vector<ll> v;
unordered_map<ll, bool> taken;

/*void MinMax(ll left, ll right, ll *mn, ll *mx) {
    ll x, y;
    cin >> x >> y;
    *mn = x;
    *mx = y;
}*/

void binSearch(ll left, ll right) {
    if (v.size() == n)
    {
        return;
    }
    if (right < left)
    {
        return;
    }
    
    MinMax(left, right, &mn, &mx);
    if (mn == -1)
    {
        return;
    }
    if (taken.find(mn) == taken.end())
    {
        taken.insert({mn, true});
        v.push_back(mn);
    }
    if (taken.find(mx) == taken.end())
    {
        taken.insert({mx, true});
        v.push_back(mx);
    }
    if (mn == mx or mn == mx -1)
    {
        return;
    }
    left = mn+1;
    right = mx-1;
    
    ll med = (left+right)/2;
    binSearch(left, med);
    binSearch(med+1, right);    
}

ll findGap(int t, int N) {
    n = N;
    ll leftPointer = 0;
    ll rightPointer = 1000000000000000000;
    if (t == 1)
    {
        while (v.size() < n)
        {
            MinMax(leftPointer, rightPointer, &mn, &mx);
            v.push_back(mn);
            v.push_back(mx);
            leftPointer = mn+1;
            rightPointer = mx-1;
        }
        sort(v.begin(), v.end());
        ll maxDiff = 0;
        for (int i = 0; i < v.size()-1; i++)
        {
            maxDiff = max(maxDiff, v[i+1]-v[i]);
        }
        return maxDiff;
    }
    binSearch(leftPointer, rightPointer);
    sort(v.begin(), v.end());
    ll maxDiff = 0;
    for (int i = 0; i < v.size()-1; i++)
    {
        maxDiff = max(maxDiff, v[i+1]-v[i]);
    }
    return maxDiff;
}

Compilation message

gap.cpp: In function 'void binSearch(ll, ll)':
gap.cpp:20:18: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   20 |     if (v.size() == n)
      |         ~~~~~~~~~^~~~
gap.cpp: In function 'll findGap(int, int)':
gap.cpp:62:25: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   62 |         while (v.size() < n)
      |                ~~~~~~~~~^~~
gap.cpp:72:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |         for (int i = 0; i < v.size()-1; i++)
      |                         ~~^~~~~~~~~~~~
gap.cpp:81:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |     for (int i = 0; i < v.size()-1; i++)
      |                     ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 20 ms 896 KB Output is correct
17 Correct 14 ms 896 KB Output is correct
18 Correct 17 ms 1064 KB Output is correct
19 Correct 14 ms 896 KB Output is correct
20 Correct 10 ms 896 KB Output is correct
21 Correct 58 ms 2288 KB Output is correct
22 Correct 57 ms 2288 KB Output is correct
23 Correct 65 ms 2448 KB Output is correct
24 Correct 56 ms 2460 KB Output is correct
25 Correct 48 ms 2288 KB Output is correct
26 Correct 57 ms 2288 KB Output is correct
27 Correct 60 ms 2288 KB Output is correct
28 Correct 63 ms 2288 KB Output is correct
29 Correct 58 ms 2288 KB Output is correct
30 Correct 43 ms 2288 KB Output is correct
31 Correct 0 ms 384 KB Output is correct
32 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Partially correct 1 ms 416 KB Partially correct
3 Partially correct 0 ms 384 KB Partially correct
4 Partially correct 0 ms 384 KB Partially correct
5 Partially correct 0 ms 384 KB Partially correct
6 Partially correct 1 ms 384 KB Partially correct
7 Partially correct 1 ms 384 KB Partially correct
8 Partially correct 1 ms 384 KB Partially correct
9 Partially correct 0 ms 384 KB Partially correct
10 Partially correct 0 ms 384 KB Partially correct
11 Partially correct 2 ms 384 KB Partially correct
12 Partially correct 2 ms 384 KB Partially correct
13 Partially correct 2 ms 384 KB Partially correct
14 Partially correct 2 ms 384 KB Partially correct
15 Partially correct 1 ms 384 KB Partially correct
16 Partially correct 22 ms 1784 KB Partially correct
17 Partially correct 22 ms 1784 KB Partially correct
18 Partially correct 22 ms 1784 KB Partially correct
19 Partially correct 23 ms 1912 KB Partially correct
20 Partially correct 14 ms 1792 KB Partially correct
21 Partially correct 99 ms 6080 KB Partially correct
22 Partially correct 100 ms 6044 KB Partially correct
23 Partially correct 95 ms 6032 KB Partially correct
24 Partially correct 99 ms 6076 KB Partially correct
25 Partially correct 71 ms 6036 KB Partially correct
26 Partially correct 99 ms 6032 KB Partially correct
27 Partially correct 96 ms 6084 KB Partially correct
28 Partially correct 97 ms 6024 KB Partially correct
29 Partially correct 108 ms 6260 KB Partially correct
30 Partially correct 59 ms 6032 KB Partially correct
31 Partially correct 0 ms 384 KB Partially correct
32 Partially correct 0 ms 384 KB Partially correct