#include <bits/stdc++.h>
#include "gap.h"
#define endl '\n'
using namespace std;
typedef long long ll;
const ll INF = 4e18;
ll t,n;
ll solve_t1()
{
vector <ll> a;
ll left = 1;
ll right = INF;
ll minel;
ll maxel;
ll cnt = 0;
while(left <= right && a.size() < n)
{
MinMax(left, right, &minel, &maxel);
a.push_back(minel);
a.push_back(maxel);
left = minel + 1;
right = maxel - 1;
}
sort(a.begin(), a.end());
ll ans = 0;
for(int i = 1; i < a.size(); i++)
{
ans = max(ans, a[i] - a[i - 1]);
}
return ans;
}
ll solve_t2()
{
ll minel;
ll maxel;
MinMax(0, INF, &minel, &maxel);
ll cnt = (maxel - minel + 1) / n;
ll ans = cnt;
ll last = minel;
ll cur = minel + 1;
while(cur <= maxel)
{
ll cur_minel;
ll cur_maxel;
MinMax(cur, cur + cnt, &cur_minel, &cur_maxel);
if(cur_minel != -1)
{
ans = max(ans, cur_minel - last);
last = cur_maxel;
}
cur += (cnt + 1);
}
return ans;
}
ll findGap(int T, int N)
{
t = T;
n = N;
if(t == 1)
return solve_t1();
else if(t == 2)
return solve_t2();
else
assert(false);
}
Compilation message
gap.cpp: In function 'll solve_t1()':
gap.cpp:23:37: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
23 | while(left <= right && a.size() < n)
| ~~~~~~~~~^~~
gap.cpp:35:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | for(int i = 1; i < a.size(); i++)
| ~~^~~~~~~~~~
gap.cpp:21:8: warning: unused variable 'cnt' [-Wunused-variable]
21 | ll cnt = 0;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
0 ms |
2392 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
13 |
Correct |
1 ms |
2392 KB |
Output is correct |
14 |
Correct |
1 ms |
2392 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
8 ms |
3008 KB |
Output is correct |
17 |
Correct |
8 ms |
2804 KB |
Output is correct |
18 |
Correct |
8 ms |
2844 KB |
Output is correct |
19 |
Correct |
9 ms |
2836 KB |
Output is correct |
20 |
Correct |
7 ms |
2824 KB |
Output is correct |
21 |
Correct |
37 ms |
3996 KB |
Output is correct |
22 |
Correct |
31 ms |
3988 KB |
Output is correct |
23 |
Correct |
31 ms |
4000 KB |
Output is correct |
24 |
Correct |
32 ms |
3932 KB |
Output is correct |
25 |
Correct |
28 ms |
3992 KB |
Output is correct |
26 |
Correct |
32 ms |
3972 KB |
Output is correct |
27 |
Correct |
31 ms |
4188 KB |
Output is correct |
28 |
Correct |
36 ms |
3988 KB |
Output is correct |
29 |
Correct |
31 ms |
3996 KB |
Output is correct |
30 |
Correct |
26 ms |
3988 KB |
Output is correct |
31 |
Correct |
1 ms |
2392 KB |
Output is correct |
32 |
Correct |
0 ms |
2392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
0 ms |
2392 KB |
Output is correct |
4 |
Correct |
0 ms |
2392 KB |
Output is correct |
5 |
Correct |
0 ms |
2392 KB |
Output is correct |
6 |
Correct |
0 ms |
2392 KB |
Output is correct |
7 |
Correct |
0 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
13 |
Correct |
1 ms |
2392 KB |
Output is correct |
14 |
Correct |
1 ms |
2392 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
10 ms |
2560 KB |
Output is correct |
17 |
Correct |
12 ms |
2828 KB |
Output is correct |
18 |
Correct |
10 ms |
2536 KB |
Output is correct |
19 |
Correct |
10 ms |
2752 KB |
Output is correct |
20 |
Correct |
6 ms |
2592 KB |
Output is correct |
21 |
Correct |
45 ms |
2852 KB |
Output is correct |
22 |
Correct |
39 ms |
2852 KB |
Output is correct |
23 |
Correct |
38 ms |
2856 KB |
Output is correct |
24 |
Correct |
40 ms |
2864 KB |
Output is correct |
25 |
Correct |
37 ms |
2852 KB |
Output is correct |
26 |
Correct |
39 ms |
2852 KB |
Output is correct |
27 |
Correct |
38 ms |
2856 KB |
Output is correct |
28 |
Correct |
39 ms |
2860 KB |
Output is correct |
29 |
Correct |
40 ms |
2856 KB |
Output is correct |
30 |
Correct |
21 ms |
2852 KB |
Output is correct |
31 |
Correct |
1 ms |
2552 KB |
Output is correct |
32 |
Correct |
1 ms |
2392 KB |
Output is correct |