Submission #26407

# Submission time Handle Problem Language Result Execution time Memory
26407 2017-06-30T04:26:28 Z zscoder Gap (APIO16_gap) C++14
100 / 100
79 ms 5924 KB
#include <bits/stdc++.h>
#include "gap.h"

using namespace std;

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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;

ll a[100001];

long long findGap(int T, int N)
{
	if(T == 1)
	{
		int l = 0; int r = N - 1;
		ll al, ar;
		al = 0; ar = ll(1e18);
		ll m, n;
		for(int i = 0; i < (N+1)/2; i++)
		{
			MinMax(al, ar, &m, &n);
			a[l] = m;
			a[r] = n;
			l++; r--;
			al = m + 1; ar = n - 1;
		}
		ll ans = 0;
		for(int i = 1; i < N; i++)
		{
			ans = max(ans, a[i] - a[i - 1]);
		}
		return ans;
	}
	else
	{
		ll amin; ll amax;
		ll m, n;
		ll maxd = 0;
		MinMax(0, ll(1e18), &amin, &amax);
		a[0] = amin;
		a[N - 1] = amax;
		if(N == 2) return (amax - amin);
		if(amax - amin == N - 1)
		{
			return 1;
		}
		ll curL = amin;
		ll l = amin + 1; ll r;
		ll d = amax - amin - 1;
		ll q = d/(N - 1);
		ll rem = d%(N - 1);
		for(int i = 0; i < N - 1; i++)
		{
			if(i < rem)
			{
				r = l + q;
			}
			else
			{
				r = l + q - 1;
			}
			MinMax(l, r, &m, &n);
			if(!(m == -1 && n == -1))
			{
				maxd = max(maxd, m - curL);
				curL = n;
			}
			l = r + 1;
		}
		maxd = max(maxd, amax - curL);
		//Remember to d the last element
		return maxd;
	}
}

# Verdict Execution time Memory Grader output
1 Correct 0 ms 5924 KB Output is correct
2 Correct 0 ms 5924 KB Output is correct
3 Correct 0 ms 5924 KB Output is correct
4 Correct 0 ms 5924 KB Output is correct
5 Correct 0 ms 5924 KB Output is correct
6 Correct 0 ms 5924 KB Output is correct
7 Correct 0 ms 5924 KB Output is correct
8 Correct 0 ms 5924 KB Output is correct
9 Correct 0 ms 5924 KB Output is correct
10 Correct 0 ms 5924 KB Output is correct
11 Correct 0 ms 5924 KB Output is correct
12 Correct 0 ms 5924 KB Output is correct
13 Correct 0 ms 5924 KB Output is correct
14 Correct 0 ms 5924 KB Output is correct
15 Correct 0 ms 5924 KB Output is correct
16 Correct 13 ms 5924 KB Output is correct
17 Correct 13 ms 5924 KB Output is correct
18 Correct 9 ms 5924 KB Output is correct
19 Correct 9 ms 5924 KB Output is correct
20 Correct 6 ms 5924 KB Output is correct
21 Correct 56 ms 5924 KB Output is correct
22 Correct 53 ms 5924 KB Output is correct
23 Correct 46 ms 5924 KB Output is correct
24 Correct 63 ms 5924 KB Output is correct
25 Correct 49 ms 5924 KB Output is correct
26 Correct 56 ms 5924 KB Output is correct
27 Correct 56 ms 5924 KB Output is correct
28 Correct 56 ms 5924 KB Output is correct
29 Correct 53 ms 5924 KB Output is correct
30 Correct 33 ms 5924 KB Output is correct
31 Correct 0 ms 5924 KB Output is correct
32 Correct 0 ms 5924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 5924 KB Output is correct
2 Correct 0 ms 5924 KB Output is correct
3 Correct 0 ms 5924 KB Output is correct
4 Correct 0 ms 5924 KB Output is correct
5 Correct 0 ms 5924 KB Output is correct
6 Correct 0 ms 5924 KB Output is correct
7 Correct 0 ms 5924 KB Output is correct
8 Correct 0 ms 5924 KB Output is correct
9 Correct 0 ms 5924 KB Output is correct
10 Correct 0 ms 5924 KB Output is correct
11 Correct 0 ms 5924 KB Output is correct
12 Correct 0 ms 5924 KB Output is correct
13 Correct 0 ms 5924 KB Output is correct
14 Correct 0 ms 5924 KB Output is correct
15 Correct 0 ms 5924 KB Output is correct
16 Correct 16 ms 5924 KB Output is correct
17 Correct 16 ms 5924 KB Output is correct
18 Correct 16 ms 5924 KB Output is correct
19 Correct 16 ms 5924 KB Output is correct
20 Correct 6 ms 5924 KB Output is correct
21 Correct 79 ms 5924 KB Output is correct
22 Correct 59 ms 5924 KB Output is correct
23 Correct 79 ms 5924 KB Output is correct
24 Correct 66 ms 5924 KB Output is correct
25 Correct 69 ms 5924 KB Output is correct
26 Correct 69 ms 5924 KB Output is correct
27 Correct 73 ms 5924 KB Output is correct
28 Correct 79 ms 5924 KB Output is correct
29 Correct 69 ms 5924 KB Output is correct
30 Correct 39 ms 5924 KB Output is correct
31 Correct 0 ms 5924 KB Output is correct
32 Correct 0 ms 5924 KB Output is correct