Submission #549831

# Submission time Handle Problem Language Result Execution time Memory
549831 2022-04-16T15:32:52 Z ToroTN Gap (APIO16_gap) C++14
100 / 100
68 ms 3352 KB
#include<bits/stdc++.h>
using namespace std;
#include "gap.h"
long long t,n,st,ed,mn,mx,ans=-1e18,gap,num;
vector<long long> l,r;
vector<pair<long long,long long> > p;
long long findGap(int T, int N)
{
	t=(long long)T;
	n=(long long)N;
	if(t==1)
	{
		st=0;
		ed=1e18;
		for(int i=1;i<=(n-1)/2+1;i++)
		{
			MinMax(st,ed,&mn,&mx);
			l.push_back(mn);
			r.push_back(mx);
			st=mn+1;
			ed=mx-1;
		}
		for(int i=1;i<l.size();i++)
		{
			ans=max(ans,l[i]-l[i-1]);
		}
		ans=max(ans,r[r.size()-1]-l[l.size()-1]);
		for(int i=r.size()-2;i>=0;i--)
		{
			ans=max(ans,r[i]-r[i+1]);
		}
		return ans;
	}else
	{
		MinMax(1,1e18,&st,&ed);
		//printf("%lld %lld\n",st,ed);
		p.push_back({st,st});
		gap=(ed-st)/(n-1);
		ans=gap;
		num=st+1;
		while(1)
		{
			MinMax(num,num+gap,&mn,&mx);
			//ans=max(ans,mn-num);
			if(mn!=-1&&mx!=-1)
			p.push_back({mn,mx});
			num+=gap+1;
			if(num>=ed)
			{
				break;
			}
		}
		for(int i=0;i<p.size();i++)
		{
			//printf("%lld %lld\n",p[i].first,p[i].second);
			if(i!=0)ans=max(ans,p[i].first-p[i-1].second);
			ans=max(ans,p[i].second-p[i].first);
		}
		return ans;
	}
}

Compilation message

gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:23:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |   for(int i=1;i<l.size();i++)
      |               ~^~~~~~~~~
gap.cpp:53:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |   for(int i=0;i<p.size();i++)
      |               ~^~~~~~~~~
# 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 1 ms 256 KB Output is correct
8 Correct 1 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 356 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 11 ms 808 KB Output is correct
17 Correct 9 ms 720 KB Output is correct
18 Correct 13 ms 716 KB Output is correct
19 Correct 10 ms 720 KB Output is correct
20 Correct 10 ms 732 KB Output is correct
21 Correct 42 ms 2000 KB Output is correct
22 Correct 42 ms 2044 KB Output is correct
23 Correct 37 ms 1908 KB Output is correct
24 Correct 46 ms 1924 KB Output is correct
25 Correct 34 ms 1972 KB Output is correct
26 Correct 42 ms 1996 KB Output is correct
27 Correct 53 ms 1996 KB Output is correct
28 Correct 37 ms 1988 KB Output is correct
29 Correct 39 ms 1908 KB Output is correct
30 Correct 39 ms 1908 KB Output is correct
31 Correct 1 ms 208 KB Output is correct
32 Correct 1 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 0 ms 208 KB Output is correct
11 Correct 2 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 16 ms 880 KB Output is correct
17 Correct 15 ms 876 KB Output is correct
18 Correct 13 ms 876 KB Output is correct
19 Correct 12 ms 888 KB Output is correct
20 Correct 10 ms 652 KB Output is correct
21 Correct 53 ms 2224 KB Output is correct
22 Correct 51 ms 2136 KB Output is correct
23 Correct 58 ms 2212 KB Output is correct
24 Correct 57 ms 2180 KB Output is correct
25 Correct 57 ms 3352 KB Output is correct
26 Correct 57 ms 2200 KB Output is correct
27 Correct 52 ms 2212 KB Output is correct
28 Correct 55 ms 2220 KB Output is correct
29 Correct 68 ms 2240 KB Output is correct
30 Correct 39 ms 1448 KB Output is correct
31 Correct 1 ms 208 KB Output is correct
32 Correct 0 ms 208 KB Output is correct