Submission #793170

# Submission time Handle Problem Language Result Execution time Memory
793170 2023-07-25T14:52:48 Z algorithm16 Gap (APIO16_gap) C++14
100 / 100
69 ms 5660 KB
#include "gap.h"
#include<iostream>
#include<set>
#include<algorithm>
using namespace std;
typedef long long int llint;
set <llint> s;
llint fnd(llint x,llint r) {
	set <llint>::iterator it=s.upper_bound(x+r);
	if(it!=s.begin()) {
		it--;
		if((*it)!=x) return (*it);
	}
	llint mn=0,mx=0;
	MinMax(x+1,x+r,&mn,&mx);
	s.insert(mn);
	s.insert(mx);
	return mx;
}
llint findGap(int T, int N)
{
	llint mn,mx;
	if(T==1) {
		llint x=1,y=1e18,r=0,cnt=0;
		while(x<y) {
			if(N==0) {
				r=max(r,y-x+2);
				break;
			}
			MinMax(x,y,&mn,&mx);
			//cout << x << " " << y << "\n";
			//cin >> mn >> mx;
			if(mn==-1 && mx==-1) {
				r=max(r,y-x+2);
				break;
			}
			if(cnt) r=max(r,mn-x+1);
			if(cnt) r=max(r,y-mx+1);
			//cout << r << "\n";
			x=mn+1;
			y=mx-1;
			cnt+=1;
			N-=2;
		}
		return r;
	}
	MinMax(1LL,(llint)1e18,&mn,&mx);
	llint x=mn,y=mx,rr=mx-mn,r=(mx-mn)/(N-1)+((mx-mn)%(N-1)!=0);
	s.insert(mn);
	s.insert(mx);
	while(x!=y) {
		llint x1=fnd(x,r);
		if(x1!=-1) {
			x=x1;
			continue;
		}
		llint lo=r,hi=min(y-x,r*4);
		while(lo<hi) {
			llint mid=(lo+hi)/2;
			llint x1=fnd(x,mid);
			if(x1!=-1) {
				lo=(*s.lower_bound(x+1))-x;
				break;
			}
			else lo=mid+1;
		}
		if(lo<min(y-x,r*4)) x+=lo;
		r=lo;
	}
	return r;
}
/*int main()
{
	cout << findGap(1,6);
	return 0;
}*/

Compilation message

gap.cpp: In function 'llint findGap(int, int)':
gap.cpp:48:18: warning: unused variable 'rr' [-Wunused-variable]
   48 |  llint x=mn,y=mx,rr=mx-mn,r=(mx-mn)/(N-1)+((mx-mn)%(N-1)!=0);
      |                  ^~
# 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 1 ms 256 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 1 ms 208 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 7 ms 464 KB Output is correct
17 Correct 7 ms 472 KB Output is correct
18 Correct 7 ms 464 KB Output is correct
19 Correct 9 ms 464 KB Output is correct
20 Correct 6 ms 516 KB Output is correct
21 Correct 35 ms 1060 KB Output is correct
22 Correct 29 ms 1068 KB Output is correct
23 Correct 29 ms 1052 KB Output is correct
24 Correct 29 ms 1068 KB Output is correct
25 Correct 24 ms 1056 KB Output is correct
26 Correct 28 ms 964 KB Output is correct
27 Correct 28 ms 1092 KB Output is correct
28 Correct 29 ms 1064 KB Output is correct
29 Correct 35 ms 976 KB Output is correct
30 Correct 24 ms 1004 KB Output is correct
31 Correct 0 ms 208 KB Output is correct
32 Correct 0 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 1 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 1 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 288 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 6 ms 816 KB Output is correct
17 Correct 6 ms 696 KB Output is correct
18 Correct 5 ms 720 KB Output is correct
19 Correct 6 ms 680 KB Output is correct
20 Correct 3 ms 464 KB Output is correct
21 Correct 21 ms 1952 KB Output is correct
22 Correct 21 ms 2096 KB Output is correct
23 Correct 20 ms 1956 KB Output is correct
24 Correct 21 ms 1956 KB Output is correct
25 Correct 69 ms 5660 KB Output is correct
26 Correct 21 ms 2100 KB Output is correct
27 Correct 22 ms 2080 KB Output is correct
28 Correct 23 ms 2072 KB Output is correct
29 Correct 22 ms 1956 KB Output is correct
30 Correct 10 ms 1360 KB Output is correct
31 Correct 1 ms 208 KB Output is correct
32 Correct 0 ms 208 KB Output is correct