Submission #771027

# Submission time Handle Problem Language Result Execution time Memory
771027 2023-07-02T11:08:06 Z boris_mihov Gap (APIO16_gap) C++17
100 / 100
48 ms 1868 KB
#include "gap.h"
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

typedef long long llong;
const int MAXN = 100000 + 10;
const int INF  = 1e9;
    
int n;
llong a[MAXN];
llong findGap(int T, int N)
{
    n = N;
    if (T == 1)
    {
        int lPtr = 1;
        int rPtr = n;
        llong lLast = 0;
        llong rLast = 1e18;
        while (lPtr <= rPtr)
        {
            MinMax(lLast, rLast, &lLast, &rLast);
            a[lPtr++] = lLast;
            a[rPtr--] = rLast;
            lLast++; rLast--;
        }

        llong max = 0;
        for (int i = 1 ; i < n ; ++i)
        {
            max = std::max(max, a[i + 1] - a[i]);
        }

        return max;
    }

    llong ans = 1;
    llong min, max;
    MinMax(0, (llong)1e18, &min, &max);
    llong gap = ((max - min + 1) / n + (((max - min + 1) % n) > 0)) * 2 - 1;

    llong last = min;
    while (last < max)
    {
        llong currMin, currMax;
        MinMax(last + 1, last + gap, &currMin, &currMax);
        if (currMin == -1)
        {
            gap *= 2;
            continue;
        }
        
        gap = currMin - last;
        ans = std::max(ans, gap);
        last = currMax;
    }

    return ans;
}
# 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 0 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 0 ms 236 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 8 ms 716 KB Output is correct
17 Correct 8 ms 688 KB Output is correct
18 Correct 8 ms 652 KB Output is correct
19 Correct 7 ms 644 KB Output is correct
20 Correct 6 ms 592 KB Output is correct
21 Correct 29 ms 1760 KB Output is correct
22 Correct 30 ms 1848 KB Output is correct
23 Correct 35 ms 1868 KB Output is correct
24 Correct 30 ms 1868 KB Output is correct
25 Correct 27 ms 1864 KB Output is correct
26 Correct 30 ms 1808 KB Output is correct
27 Correct 35 ms 1768 KB Output is correct
28 Correct 30 ms 1844 KB Output is correct
29 Correct 30 ms 1828 KB Output is correct
30 Correct 25 ms 1784 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 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 1 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 9 ms 460 KB Output is correct
17 Correct 11 ms 512 KB Output is correct
18 Correct 10 ms 516 KB Output is correct
19 Correct 10 ms 520 KB Output is correct
20 Correct 5 ms 464 KB Output is correct
21 Correct 46 ms 968 KB Output is correct
22 Correct 38 ms 1064 KB Output is correct
23 Correct 38 ms 1080 KB Output is correct
24 Correct 40 ms 1084 KB Output is correct
25 Correct 40 ms 1104 KB Output is correct
26 Correct 40 ms 1032 KB Output is correct
27 Correct 48 ms 1092 KB Output is correct
28 Correct 45 ms 1084 KB Output is correct
29 Correct 39 ms 1080 KB Output is correct
30 Correct 18 ms 1064 KB Output is correct
31 Correct 0 ms 208 KB Output is correct
32 Correct 0 ms 208 KB Output is correct