Submission #40159

# Submission time Handle Problem Language Result Execution time Memory
40159 2018-01-28T17:21:16 Z SpaimaCarpatilor Gap (APIO16_gap) C++14
100 / 100
83 ms 5928 KB
#include "gap.h"
#include<bits/stdc++.h>

using namespace std;

long long x[100009];
const long long xmax = 1e18;

long long rand15 () {return rand () & 32767;}
long long rand30 () {return (rand15 () << 15LL) | rand15 ();}
long long rand60 () {return (rand30 () << 30LL) | rand30 ();}

long long findGap(int T, int N)
{
    srand (time (0));
    if (T == 1)
    {
        long long a = 0, b = xmax;
        for (int i = 1, j = N; i<=j; i ++, j --)
            MinMax (a, b, &x[i], &x[j]), a = x[i] + 1, b = x[j] - 1;
        long long ans = x[2] - x[1];
        for (int i=1; i<N; i++)
            if (x[i + 1] - x[i] > ans)
                ans = x[i + 1] - x[i];
        return ans;
    }
    long long mi, ma;
    MinMax (0, xmax, &mi, &ma);
    long long L = (ma - mi) / (N - 1) + ((ma - mi) % (N - 1) != 0);
    int nr = 0;
    long long st = mi + 1;
    x[1] = mi, nr = 1;
    while (st < ma)
    {
        long long dr = st + L - 1, y, z;
        if (dr >= ma) dr = ma - 1;
        MinMax (st, dr, &y, &z);
        if (y != -1) x[++nr] = y;
        if (y != z) x[++nr] = z;
        st = dr + 1;
    }
    x[++nr] = ma;
    long long ans = x[2] - x[1];
    for (int i=2; i<nr; i++)
        ans = max (ans, x[i + 1] - x[i]);
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 5928 KB Output is correct
2 Correct 0 ms 5928 KB Output is correct
3 Correct 0 ms 5928 KB Output is correct
4 Correct 0 ms 5928 KB Output is correct
5 Correct 0 ms 5928 KB Output is correct
6 Correct 0 ms 5928 KB Output is correct
7 Correct 0 ms 5928 KB Output is correct
8 Correct 0 ms 5928 KB Output is correct
9 Correct 0 ms 5928 KB Output is correct
10 Correct 0 ms 5928 KB Output is correct
11 Correct 1 ms 5928 KB Output is correct
12 Correct 0 ms 5928 KB Output is correct
13 Correct 1 ms 5928 KB Output is correct
14 Correct 1 ms 5928 KB Output is correct
15 Correct 1 ms 5928 KB Output is correct
16 Correct 15 ms 5928 KB Output is correct
17 Correct 16 ms 5928 KB Output is correct
18 Correct 16 ms 5928 KB Output is correct
19 Correct 14 ms 5928 KB Output is correct
20 Correct 13 ms 5928 KB Output is correct
21 Correct 51 ms 5928 KB Output is correct
22 Correct 55 ms 5928 KB Output is correct
23 Correct 62 ms 5928 KB Output is correct
24 Correct 45 ms 5928 KB Output is correct
25 Correct 54 ms 5928 KB Output is correct
26 Correct 58 ms 5928 KB Output is correct
27 Correct 57 ms 5928 KB Output is correct
28 Correct 48 ms 5928 KB Output is correct
29 Correct 45 ms 5928 KB Output is correct
30 Correct 35 ms 5928 KB Output is correct
31 Correct 0 ms 5928 KB Output is correct
32 Correct 0 ms 5928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 5928 KB Output is correct
2 Correct 0 ms 5928 KB Output is correct
3 Correct 0 ms 5928 KB Output is correct
4 Correct 0 ms 5928 KB Output is correct
5 Correct 0 ms 5928 KB Output is correct
6 Correct 0 ms 5928 KB Output is correct
7 Correct 0 ms 5928 KB Output is correct
8 Correct 1 ms 5928 KB Output is correct
9 Correct 1 ms 5928 KB Output is correct
10 Correct 0 ms 5928 KB Output is correct
11 Correct 2 ms 5928 KB Output is correct
12 Correct 1 ms 5928 KB Output is correct
13 Correct 1 ms 5928 KB Output is correct
14 Correct 1 ms 5928 KB Output is correct
15 Correct 0 ms 5928 KB Output is correct
16 Correct 19 ms 5928 KB Output is correct
17 Correct 19 ms 5928 KB Output is correct
18 Correct 19 ms 5928 KB Output is correct
19 Correct 19 ms 5928 KB Output is correct
20 Correct 8 ms 5928 KB Output is correct
21 Correct 70 ms 5928 KB Output is correct
22 Correct 73 ms 5928 KB Output is correct
23 Correct 78 ms 5928 KB Output is correct
24 Correct 72 ms 5928 KB Output is correct
25 Correct 68 ms 5928 KB Output is correct
26 Correct 73 ms 5928 KB Output is correct
27 Correct 83 ms 5928 KB Output is correct
28 Correct 73 ms 5928 KB Output is correct
29 Correct 73 ms 5928 KB Output is correct
30 Correct 35 ms 5928 KB Output is correct
31 Correct 0 ms 5928 KB Output is correct
32 Correct 0 ms 5928 KB Output is correct