#include "gap.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
long long findGap(int T, int N)
{
if (T==1)
{
ll x=0, y=1e18, a, b, idx=0, mx=0;
vector<ll> v;
while (v.size()<N)
{
MinMax(x, y, &a, &b);
if (a==b) v.push_back(a);
else v.push_back(a), v.push_back(b);
x=a+1; y=b-1;
}
sort(v.begin(), v.end());
for (int i=1; i<v.size(); i++) mx=max(mx, v[i]-v[i-1]);
return mx;
}
else
{
ll x=0, y=1e18, mn, mx, mmn, mmx, res=0, cnt=0, lst;
vector<ll> v;
MinMax(x, y, &mmn, &mmx);
if (mmx-mmn+1<N+1) return 1;
ll gap=(mmx-mmn-1)/(N-1), rem=(mmx-mmn-1)%(N-1);
cout<<rem<<'\n';
v.push_back(mmn);
v.push_back(mmx);
lst=mmn+1;
for (ll i=mmn+1; i<=mmx-1&&cnt<rem; i+=gap+1, cnt++)
{
MinMax(i, i+gap, &mn, &mx);
lst=i+gap+1;
if (mn==-1) continue;
v.push_back(mn);
if (mn!=mx) v.push_back(mx);
}
for (ll i=lst; i<=mmx-1; i+=gap)
{
MinMax(i, i+gap-1, &mn, &mx);
if (mn==-1) continue;
v.push_back(mn);
if (mn!=mx) v.push_back(mx);
}
sort(v.begin(), v.end());
for (int i=1; i<v.size(); i++) res=max(res, v[i]-v[i-1]);
return res;
}
}
Compilation message
gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:15:24: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
15 | while (v.size()<N)
| ~~~~~~~~^~
gap.cpp:23:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | for (int i=1; i<v.size(); i++) mx=max(mx, v[i]-v[i-1]);
| ~^~~~~~~~~
gap.cpp:13:31: warning: unused variable 'idx' [-Wunused-variable]
13 | ll x=0, y=1e18, a, b, idx=0, mx=0;
| ^~~
gap.cpp:53:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | for (int i=1; i<v.size(); i++) res=max(res, v[i]-v[i-1]);
| ~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 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 |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
0 ms |
2392 KB |
Output is correct |
8 |
Correct |
0 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
0 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 |
9 ms |
2832 KB |
Output is correct |
17 |
Correct |
8 ms |
2836 KB |
Output is correct |
18 |
Correct |
8 ms |
2812 KB |
Output is correct |
19 |
Correct |
8 ms |
3016 KB |
Output is correct |
20 |
Correct |
7 ms |
2828 KB |
Output is correct |
21 |
Correct |
32 ms |
3996 KB |
Output is correct |
22 |
Correct |
36 ms |
4208 KB |
Output is correct |
23 |
Correct |
32 ms |
4000 KB |
Output is correct |
24 |
Correct |
32 ms |
3996 KB |
Output is correct |
25 |
Correct |
29 ms |
3988 KB |
Output is correct |
26 |
Correct |
32 ms |
4000 KB |
Output is correct |
27 |
Correct |
32 ms |
3988 KB |
Output is correct |
28 |
Correct |
32 ms |
3996 KB |
Output is correct |
29 |
Correct |
32 ms |
3992 KB |
Output is correct |
30 |
Correct |
26 ms |
3924 KB |
Output is correct |
31 |
Correct |
1 ms |
2392 KB |
Output is correct |
32 |
Correct |
1 ms |
2392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
Expected int32, but "527609318252951603" found |
2 |
Incorrect |
1 ms |
2392 KB |
Expected int32, but "158717465145313148" found |
3 |
Incorrect |
1 ms |
2392 KB |
Expected int32, but "141470620841118761" found |
4 |
Incorrect |
0 ms |
2392 KB |
Expected int32, but "281070690232818333" found |
5 |
Incorrect |
0 ms |
2392 KB |
Expected EOF |
6 |
Incorrect |
0 ms |
2392 KB |
Expected int32, but "54067555940387079" found |
7 |
Incorrect |
0 ms |
2392 KB |
Expected int32, but "59713872839546348" found |
8 |
Incorrect |
0 ms |
2392 KB |
Expected int32, but "63628383529967709" found |
9 |
Incorrect |
1 ms |
2392 KB |
Expected int32, but "40066697874077492" found |
10 |
Incorrect |
0 ms |
2392 KB |
Expected EOF |
11 |
Incorrect |
1 ms |
2392 KB |
Expected int32, but "4966493272906105" found |
12 |
Incorrect |
1 ms |
2484 KB |
Expected int32, but "4541692825618767" found |
13 |
Incorrect |
1 ms |
2392 KB |
Expected int32, but "4642293045041442" found |
14 |
Incorrect |
1 ms |
2392 KB |
Expected int32, but "6122034287537034" found |
15 |
Incorrect |
1 ms |
2392 KB |
Expected EOF |
16 |
Incorrect |
11 ms |
2816 KB |
Expected int32, but "410686271327381" found |
17 |
Incorrect |
11 ms |
2972 KB |
Expected int32, but "430267194921600" found |
18 |
Incorrect |
11 ms |
2836 KB |
Expected int32, but "487268024112545" found |
19 |
Incorrect |
10 ms |
2904 KB |
Expected int32, but "599893247137814" found |
20 |
Incorrect |
5 ms |
2584 KB |
Expected EOF |
21 |
Incorrect |
41 ms |
4016 KB |
Expected int32, but "130710364094545" found |
22 |
Incorrect |
41 ms |
3928 KB |
Expected int32, but "120119470217307" found |
23 |
Incorrect |
41 ms |
3984 KB |
Expected int32, but "131100462117639" found |
24 |
Incorrect |
41 ms |
3984 KB |
Expected int32, but "147711566772217" found |
25 |
Incorrect |
41 ms |
3992 KB |
Expected EOF |
26 |
Incorrect |
43 ms |
3992 KB |
Expected int32, but "162924923640912" found |
27 |
Incorrect |
47 ms |
3972 KB |
Expected int32, but "117217672541541" found |
28 |
Incorrect |
41 ms |
3988 KB |
Expected int32, but "109432203596644" found |
29 |
Incorrect |
41 ms |
4248 KB |
Expected int32, but "123267759045505" found |
30 |
Incorrect |
23 ms |
3100 KB |
Expected EOF |
31 |
Incorrect |
0 ms |
2392 KB |
Expected int32, but "500000000000000000" found |
32 |
Incorrect |
1 ms |
2388 KB |
Expected int32, but "500000000000000000" found |