답안 #744961

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
744961 2023-05-19T09:03:28 Z amirhoseinfar1385 Gap (APIO16_gap) C++17
100 / 100
47 ms 1868 KB
#include<bits/stdc++.h>
#include "gap.h"
using namespace std;

long long findGap(int T, int N)
{
	if(T==1||N<=8){
		vector<long long>all(N);
		long long mn=-1,mx=((long long)1e18+5),fmn=0,fmx=0;
		//cout<<mx<<"\n";
		int last=N-1,first=0;
		while(last>=first){
			MinMax(mn+1,mx-1,&fmn,&fmx);
			//cout<<first<<" "<<last<<" "<<mn+1<<" "<<mx-1<<" "<<fmn<<" "<<fmx<<'\n';
			mn=fmn;
			mx=fmx;
			all[last]=mx;
			all[first]=mn;
			last--;
			first++;
		}
		long long res=0;
		for(int i=1;i<N;i++){
		//	cout<<all[i]<<" "<<all[i-1]<<'\n';
			res=max(res,all[i]-all[i-1]);
		}
		return res;
	}
	else{
		long long res=1;
		long long mn=-1,mx=((long long)1e18+5),fmn=0,fmx=0;
		MinMax(mn+1,mx-1,&fmn,&fmx);
		mn=fmn;
		mx=fmx;
		res=(mx-mn)/N;
		while(mn+res-1<mx){
			//cout<<mn<<" asda "<<res<<endl;
			MinMax(mn+1,mn+res,&fmn,&fmx);
			//cout<<fmn<<" edasdb "<<fmx<<endl;
			if(fmn==-1){
				break;
			}
			mn=fmx;
		}
		//cout<<mn<<" "<<mx<<endl;
		while(mn+res-1<mx){
			//cout<<mn<<" asd "<<res<<endl;
			MinMax(mn+res,mn+res+res,&fmn,&fmx);
			if(fmn==-1){
				res*=2;
				res++;
				continue;
			}
			res=max(res,fmn-mn);
			mn=fmx;
			while(mn+res-1<mx){
				//cout<<mn<<" asda "<<res<<endl;
				MinMax(mn+1,mn+res,&fmn,&fmx);
				//cout<<fmn<<" edasdb "<<fmx<<endl;
				if(fmn==-1){
					break;
				}
				mn=fmx;
			}
			//cout<<mn<<" asdb "<<res<<endl;
		}
		//cout<<res<<endl;
		return res;
	}
}
# 결과 실행 시간 메모리 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 1 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 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 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 9 ms 720 KB Output is correct
17 Correct 9 ms 720 KB Output is correct
18 Correct 9 ms 672 KB Output is correct
19 Correct 10 ms 720 KB Output is correct
20 Correct 8 ms 628 KB Output is correct
21 Correct 36 ms 1824 KB Output is correct
22 Correct 35 ms 1828 KB Output is correct
23 Correct 33 ms 1828 KB Output is correct
24 Correct 35 ms 1788 KB Output is correct
25 Correct 30 ms 1832 KB Output is correct
26 Correct 34 ms 1868 KB Output is correct
27 Correct 35 ms 1864 KB Output is correct
28 Correct 35 ms 1828 KB Output is correct
29 Correct 34 ms 1860 KB Output is correct
30 Correct 29 ms 1836 KB Output is correct
31 Correct 0 ms 208 KB Output is correct
32 Correct 0 ms 208 KB Output is correct
# 결과 실행 시간 메모리 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 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 208 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 8 ms 464 KB Output is correct
17 Correct 6 ms 508 KB Output is correct
18 Correct 6 ms 428 KB Output is correct
19 Correct 6 ms 432 KB Output is correct
20 Correct 3 ms 460 KB Output is correct
21 Correct 22 ms 968 KB Output is correct
22 Correct 23 ms 1036 KB Output is correct
23 Correct 22 ms 976 KB Output is correct
24 Correct 23 ms 1036 KB Output is correct
25 Correct 47 ms 1080 KB Output is correct
26 Correct 23 ms 1064 KB Output is correct
27 Correct 27 ms 1016 KB Output is correct
28 Correct 24 ms 984 KB Output is correct
29 Correct 23 ms 1188 KB Output is correct
30 Correct 12 ms 1104 KB Output is correct
31 Correct 0 ms 208 KB Output is correct
32 Correct 0 ms 208 KB Output is correct