#include "gap.h"
#include <bits/stdc++.h>
#define LLMAX 1000000000000000000LL
long long findGap1(int N){
long long mn, mx;
long long a[N];
MinMax(1, LLMAX, &mn, &mx);
a[0]=mn;
a[N-1]=mx;
for(int i=1; i<=N-1-i; ++i){
MinMax(a[i-1]+1, a[N-i]-1, &mn, &mx);
a[i]=mn;
a[N-i-1]=mx;
}
long long maxdiff=1;
for(int i=0; i<N-1; ++i){
if(a[i+1]-a[i]>maxdiff)
maxdiff=a[i+1]-a[i];
}
return maxdiff;
}
long long findGap2(int N)
{
if(N<=10)return findGap1(N);
long long apsmin, apsmax;
long long g=1, gg=1;
while(1){
long long mn, mx;
MinMax(1, g+1, &mn, &mx);
if(mn!=-1){
apsmin=mn;
break;
}
if(N>50)g*=20;
else g*=35;
}
long long last=apsmin;
while(1){
long long mn, mx;
bool kraj=false;
if(last+g<LLMAX)
MinMax(last+1, last+g, &mn, &mx);
else {
MinMax(last+1, LLMAX, &mn,&mx);
kraj=true;
}
if(mn==-1){
g=(long long)g*(2.7)+1;
if(!kraj)
continue;
else break;
}
if(mn-last>gg){
gg=mn-last;
g=gg+1;
}
last=mx;
if(kraj)break;
}
return gg;
}
long long findGap(int T, int N){
if(T==1)return findGap1(N);
return findGap2(N);
}
Compilation message
gap.cpp: In function 'long long int findGap2(int)':
gap.cpp:29:20: warning: unused variable 'apsmax' [-Wunused-variable]
long long apsmin, apsmax;
^~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
3 ms |
348 KB |
Output is correct |
16 |
Correct |
14 ms |
768 KB |
Output is correct |
17 |
Correct |
14 ms |
768 KB |
Output is correct |
18 |
Correct |
15 ms |
768 KB |
Output is correct |
19 |
Correct |
15 ms |
768 KB |
Output is correct |
20 |
Correct |
10 ms |
768 KB |
Output is correct |
21 |
Correct |
52 ms |
1912 KB |
Output is correct |
22 |
Correct |
55 ms |
1912 KB |
Output is correct |
23 |
Correct |
57 ms |
1908 KB |
Output is correct |
24 |
Correct |
58 ms |
1888 KB |
Output is correct |
25 |
Correct |
49 ms |
1912 KB |
Output is correct |
26 |
Correct |
52 ms |
1912 KB |
Output is correct |
27 |
Correct |
56 ms |
1912 KB |
Output is correct |
28 |
Correct |
69 ms |
1916 KB |
Output is correct |
29 |
Correct |
53 ms |
1912 KB |
Output is correct |
30 |
Correct |
40 ms |
1916 KB |
Output is correct |
31 |
Correct |
2 ms |
384 KB |
Output is correct |
32 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Partially correct |
2 ms |
384 KB |
Partially correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
14 ms |
512 KB |
Output is correct |
17 |
Correct |
11 ms |
512 KB |
Output is correct |
18 |
Correct |
10 ms |
640 KB |
Output is correct |
19 |
Correct |
10 ms |
512 KB |
Output is correct |
20 |
Correct |
7 ms |
512 KB |
Output is correct |
21 |
Correct |
43 ms |
1148 KB |
Output is correct |
22 |
Correct |
34 ms |
1144 KB |
Output is correct |
23 |
Correct |
34 ms |
1152 KB |
Output is correct |
24 |
Correct |
42 ms |
1272 KB |
Output is correct |
25 |
Correct |
65 ms |
1144 KB |
Output is correct |
26 |
Correct |
35 ms |
1152 KB |
Output is correct |
27 |
Correct |
31 ms |
1144 KB |
Output is correct |
28 |
Correct |
34 ms |
1072 KB |
Output is correct |
29 |
Correct |
41 ms |
1144 KB |
Output is correct |
30 |
Correct |
34 ms |
1152 KB |
Output is correct |
31 |
Correct |
2 ms |
384 KB |
Output is correct |
32 |
Correct |
2 ms |
384 KB |
Output is correct |