Submission #226543

# Submission time Handle Problem Language Result Execution time Memory
226543 2020-04-24T08:12:27 Z bharat2002 Gap (APIO16_gap) C++14
100 / 100
80 ms 1916 KB
/*input

*/
#include "gap.h" 
#include<bits/stdc++.h>
using namespace std;
const int N=1e5 + 100;
const int mod=1e9 + 7;
#define int long long
const int inf=1e18;
#define pii pair<int, int>
#define f first
#define s second 
#define mp make_pair
#define FOR(i, n) for(int i=1;i<=n;i++)
#define TRACE(x) cerr << #x << " = " << x << endl 
//Trace prints the name of the variable and the value.
int arr[N];
/*int vals[N];int nc;
void MinMax(int l, int r, int &a, int &b)
{
	for(int i=1;i<N;i++)
	{
		if(vals[i]>=l) {a=vals[i];break;}
	}
	for(int i=1;i<N;i++)
	{
		if(vals[i+1]>r||i==nc) {b=vals[i];return;}
	}
}*/
#undef int long long
long long findGap(int t, int n)
{
#define int long long
	if(t==1)
	{	
		MinMax(0, 1e18, &arr[1], &arr[n]);
		int i=2;
		while(i<=n-i+1)
		{
			MinMax(arr[i-1] + 1, arr[n-i+2]-1, &arr[i], &arr[n-i+1]);i++;
		}
		int ans=-inf;
		for(int j=1;j<n;j++) ans=max(ans, arr[j+1]-arr[j]);
		return ans;
	}
	MinMax(0, 1e18, &arr[1], &arr[n]);
	if(n==2) return arr[n]-arr[1];
	int diff=(arr[n]-arr[1])/(n-1);
	if((arr[n]-arr[1])%(n-1)!=0) diff++;
	int ans=0;
	int prevel=arr[1], curl=arr[1]+1, curr=arr[1]+1+diff;
	while(curl<arr[n])
	{
		int cmin, cmax;MinMax(curl, curr, &cmin, &cmax);
		if(cmin!=-1) ans=max(ans, cmin-prevel);
		ans=max(ans, cmax - cmin);
		if(cmax!=-1) prevel=cmax;
		curl=curr + 1;curr=curl + diff;
	}
	return ans;
}
/*signed main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int t, n;cin>>t>>n;nc=n;
	for(int i=1;i<=n;i++) cin>>vals[i];
	cout<<findGap(t, n);
}*/

Compilation message

gap.cpp:31:12: warning: extra tokens at end of #undef directive
 #undef int long long
            ^~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 16 ms 768 KB Output is correct
17 Correct 16 ms 768 KB Output is correct
18 Correct 17 ms 768 KB Output is correct
19 Correct 16 ms 768 KB Output is correct
20 Correct 13 ms 768 KB Output is correct
21 Correct 64 ms 1892 KB Output is correct
22 Correct 61 ms 1912 KB Output is correct
23 Correct 53 ms 1896 KB Output is correct
24 Correct 54 ms 1912 KB Output is correct
25 Correct 46 ms 1912 KB Output is correct
26 Correct 55 ms 1912 KB Output is correct
27 Correct 53 ms 1912 KB Output is correct
28 Correct 53 ms 1912 KB Output is correct
29 Correct 58 ms 1912 KB Output is correct
30 Correct 45 ms 1916 KB Output is correct
31 Correct 4 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 512 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 308 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 20 ms 512 KB Output is correct
17 Correct 20 ms 640 KB Output is correct
18 Correct 20 ms 592 KB Output is correct
19 Correct 22 ms 480 KB Output is correct
20 Correct 13 ms 512 KB Output is correct
21 Correct 71 ms 1124 KB Output is correct
22 Correct 80 ms 1172 KB Output is correct
23 Correct 70 ms 1144 KB Output is correct
24 Correct 72 ms 1068 KB Output is correct
25 Correct 64 ms 1132 KB Output is correct
26 Correct 80 ms 1176 KB Output is correct
27 Correct 78 ms 1172 KB Output is correct
28 Correct 70 ms 1144 KB Output is correct
29 Correct 72 ms 1172 KB Output is correct
30 Correct 42 ms 1056 KB Output is correct
31 Correct 4 ms 384 KB Output is correct
32 Correct 4 ms 384 KB Output is correct