Submission #502967

# Submission time Handle Problem Language Result Execution time Memory
502967 2022-01-06T20:40:02 Z doowey Gap (APIO16_gap) C++14
100 / 100
52 ms 3216 KB
#include <bits/stdc++.h>
#include "gap.h"

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair

long long findGap(int T, int N){
    if(T == 1){
        ll low = -1, high = (ll)1e18 + 1;
        vector<ll> C(N);
        int L = 0, R = N - 1;
        for(int i = 0 ; i < (N + 1) / 2; i ++ ){
            MinMax(low + 1, high - 1, &low, &high);
            C[L] = low;
            C[R] = high;
            L ++ ;
            R -- ;
        }
        ll res = 0;
        for(int i = 1; i < N; i ++ ){
            res = max(res, C[i] - C[i - 1]);
        }
        return res;
    }
    ll low=0, high=0;
    ll lim = (ll)1e18;
    MinMax(0ll, lim, &low, &high);
    ll S = (high - low + (N - 1) - 1) / (N - 1); // the gap is atleast S
    ll gl = low + 1;
    ll gr;
    vector<ll> in;
    in.push_back(low);
    if(N >= 3){
        ll ca, cb;
        while(gl <= high){
            gr = min(high - 1, gl + S);
            MinMax(gl, gr, &ca, &cb);
            gl += S + 1;
            if(ca == -1) continue;
            in.push_back(ca);
            in.push_back(cb);
        }
    }
    in.push_back(high);
    ll res = 0;
    for(int i = 1; i < in.size(); i ++ ){
        res = max(res, in[i] - in[i - 1]);
    }
	return res;
}

Compilation message

gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:52:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |     for(int i = 1; i < in.size(); i ++ ){
      |                    ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 200 KB Output is correct
2 Correct 0 ms 200 KB Output is correct
3 Correct 0 ms 200 KB Output is correct
4 Correct 0 ms 200 KB Output is correct
5 Correct 0 ms 200 KB Output is correct
6 Correct 0 ms 200 KB Output is correct
7 Correct 1 ms 200 KB Output is correct
8 Correct 0 ms 200 KB Output is correct
9 Correct 0 ms 200 KB Output is correct
10 Correct 0 ms 200 KB Output is correct
11 Correct 1 ms 328 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Correct 1 ms 328 KB Output is correct
15 Correct 1 ms 328 KB Output is correct
16 Correct 9 ms 712 KB Output is correct
17 Correct 8 ms 712 KB Output is correct
18 Correct 9 ms 712 KB Output is correct
19 Correct 9 ms 684 KB Output is correct
20 Correct 7 ms 712 KB Output is correct
21 Correct 34 ms 1820 KB Output is correct
22 Correct 38 ms 1824 KB Output is correct
23 Correct 37 ms 1816 KB Output is correct
24 Correct 35 ms 1820 KB Output is correct
25 Correct 30 ms 1868 KB Output is correct
26 Correct 40 ms 1856 KB Output is correct
27 Correct 40 ms 1764 KB Output is correct
28 Correct 44 ms 1876 KB Output is correct
29 Correct 33 ms 1812 KB Output is correct
30 Correct 27 ms 1884 KB Output is correct
31 Correct 0 ms 200 KB Output is correct
32 Correct 0 ms 200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 200 KB Output is correct
2 Correct 0 ms 200 KB Output is correct
3 Correct 0 ms 200 KB Output is correct
4 Correct 0 ms 200 KB Output is correct
5 Correct 0 ms 200 KB Output is correct
6 Correct 0 ms 200 KB Output is correct
7 Correct 0 ms 200 KB Output is correct
8 Correct 0 ms 200 KB Output is correct
9 Correct 0 ms 200 KB Output is correct
10 Correct 0 ms 200 KB Output is correct
11 Correct 1 ms 328 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Correct 1 ms 328 KB Output is correct
15 Correct 1 ms 328 KB Output is correct
16 Correct 13 ms 900 KB Output is correct
17 Correct 12 ms 872 KB Output is correct
18 Correct 12 ms 904 KB Output is correct
19 Correct 14 ms 840 KB Output is correct
20 Correct 6 ms 456 KB Output is correct
21 Correct 52 ms 2280 KB Output is correct
22 Correct 48 ms 2232 KB Output is correct
23 Correct 49 ms 2196 KB Output is correct
24 Correct 48 ms 2224 KB Output is correct
25 Correct 46 ms 3216 KB Output is correct
26 Correct 50 ms 2196 KB Output is correct
27 Correct 48 ms 2192 KB Output is correct
28 Correct 50 ms 2180 KB Output is correct
29 Correct 50 ms 2232 KB Output is correct
30 Correct 25 ms 1460 KB Output is correct
31 Correct 1 ms 200 KB Output is correct
32 Correct 1 ms 200 KB Output is correct