#include<bits/stdc++.h>
#include "gap.h"
using namespace std;
long long v[100002];
long long findGap(int T, int N)
{
long long ans = 0;
long long st = 0;
long long dr = 1;
for(int i = 1; i <= 18; ++i)
dr = dr * 10LL;
if(T == 1)
{
int a = 1;
int b = N;
while(a <= b)
{
long long st2;
long long dr2;
if(a == 1)
MinMax(st, dr, &st2, &dr2);
else
MinMax(st+1, dr-1, &st2, &dr2);
v[a] = st2;
v[b] = dr2;
++a;
--b;
st = st2;
dr = dr2;
}
for(int i = 1; i < N; ++i)
ans = max(ans, v[i+1] - v[i]);
}
else
{
long long st2;
long long dr2;
MinMax(st, dr, &st2, &dr2);
st = st2;
dr = dr2;
long long max_val = dr;
ans = (dr - st) / (N - 1);
while(st <= max_val)
{
dr = min(max_val, st + ans);
if(max_val - st <= ans)
break;
long long sst = st + 1;
while(1)
{
long long st2;
long long dr2;
MinMax(sst, dr, &st2, &dr2);
if(dr2 == -1)
{
sst = dr + 1;
dr = min(max_val, dr + ans);
}
else
{
ans = max(ans, st2 - st);
st = dr2;
break;
}
}
}
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
380 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
3 ms |
376 KB |
Output is correct |
12 |
Correct |
3 ms |
452 KB |
Output is correct |
13 |
Correct |
3 ms |
380 KB |
Output is correct |
14 |
Correct |
3 ms |
376 KB |
Output is correct |
15 |
Correct |
3 ms |
376 KB |
Output is correct |
16 |
Correct |
15 ms |
1272 KB |
Output is correct |
17 |
Correct |
15 ms |
1144 KB |
Output is correct |
18 |
Correct |
16 ms |
1272 KB |
Output is correct |
19 |
Correct |
15 ms |
1144 KB |
Output is correct |
20 |
Correct |
11 ms |
888 KB |
Output is correct |
21 |
Correct |
56 ms |
2672 KB |
Output is correct |
22 |
Correct |
55 ms |
2936 KB |
Output is correct |
23 |
Correct |
55 ms |
2808 KB |
Output is correct |
24 |
Correct |
55 ms |
2808 KB |
Output is correct |
25 |
Correct |
47 ms |
2808 KB |
Output is correct |
26 |
Correct |
55 ms |
2752 KB |
Output is correct |
27 |
Correct |
55 ms |
2812 KB |
Output is correct |
28 |
Correct |
55 ms |
2808 KB |
Output is correct |
29 |
Correct |
55 ms |
2808 KB |
Output is correct |
30 |
Correct |
41 ms |
2552 KB |
Output is correct |
31 |
Correct |
2 ms |
376 KB |
Output is correct |
32 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
3 ms |
376 KB |
Output is correct |
12 |
Correct |
3 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
3 ms |
376 KB |
Output is correct |
16 |
Correct |
11 ms |
1016 KB |
Output is correct |
17 |
Correct |
11 ms |
1016 KB |
Output is correct |
18 |
Correct |
11 ms |
1020 KB |
Output is correct |
19 |
Correct |
11 ms |
1016 KB |
Output is correct |
20 |
Correct |
7 ms |
632 KB |
Output is correct |
21 |
Correct |
36 ms |
2296 KB |
Output is correct |
22 |
Correct |
36 ms |
2424 KB |
Output is correct |
23 |
Correct |
37 ms |
2296 KB |
Output is correct |
24 |
Correct |
36 ms |
2296 KB |
Output is correct |
25 |
Correct |
67 ms |
2296 KB |
Output is correct |
26 |
Correct |
36 ms |
2296 KB |
Output is correct |
27 |
Correct |
37 ms |
2296 KB |
Output is correct |
28 |
Correct |
37 ms |
2296 KB |
Output is correct |
29 |
Correct |
36 ms |
2296 KB |
Output is correct |
30 |
Correct |
27 ms |
1784 KB |
Output is correct |
31 |
Correct |
2 ms |
376 KB |
Output is correct |
32 |
Correct |
2 ms |
376 KB |
Output is correct |