#include "gap.h"
#include <bits/stdc++.h>
using namespace std;
// int cnt;
// vector<long long> li;
// void MinMax(long long a, long long b, long long *c, long long *d){
// cnt++;
// vector<long long> ar;
// for(int i = 0; i<li.size(); i++){
// if(li[i]>=a && li[i]<=b){
// ar.push_back(li[i]);
// }
// }
// if(ar.size()==0){
// *c = -1;
// *d = -1;
// }
// else{
// *c = ar[0];
// *d = ar[ar.size()-1];
// }
// }
long long findGap(int T, int N)
{
long long maxval = 1000000000000000000LL;
long long mn, mx;
vector<long long> all;
long long ans = 0LL;
if(T==1){
int maxim = (N+1)/2;
long long l = 1LL;
long long r = maxval;
for(int i = 0; i<maxim; i++){
MinMax(l,r,&mn,&mx);
all.push_back(mn);
all.push_back(mx);
l = mn+1;
r = mx-1;
}
sort(all.begin(),all.end());
}
else{
MinMax(1,maxval,&mn,&mx);
long long s = mn;
long long e = mx;
if(N==1){
return e-s;
}
ans = (e-s)/((long long)N-1LL)-1LL;
if((e-s)%((long long)N-1LL)!=0){
ans++;
}
long long last = s;
long long check = ans+1LL;
all.push_back(s);
for(long long i = s+1LL; i<e; i+=check){
long long r = min(e-1LL,i+check-1LL);
MinMax(i,r,&mn,&mx);
if(mn!=-1){
all.push_back(mn);
all.push_back(mx);
}
}
all.push_back(e);
}
for(int i = 1; i<all.size(); i++){
ans = max(ans,all[i]-all[i-1]);
}
return ans;
}
// int main(){
// cnt = 0;
// li.push_back(2);
// li.push_back(3);
// li.push_back(6);
// li.push_back(8);
// cout << findGap(1,4) << endl;
// cout << cnt << endl;
// }
Compilation message
gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:53:19: warning: unused variable 'last' [-Wunused-variable]
long long last = s;
^
gap.cpp:66:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 1; i<all.size(); i++){
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
248 KB |
Output is correct |
2 |
Correct |
1 ms |
352 KB |
Output is correct |
3 |
Correct |
2 ms |
552 KB |
Output is correct |
4 |
Correct |
1 ms |
552 KB |
Output is correct |
5 |
Correct |
1 ms |
552 KB |
Output is correct |
6 |
Correct |
1 ms |
552 KB |
Output is correct |
7 |
Correct |
1 ms |
552 KB |
Output is correct |
8 |
Correct |
1 ms |
552 KB |
Output is correct |
9 |
Correct |
1 ms |
552 KB |
Output is correct |
10 |
Correct |
1 ms |
552 KB |
Output is correct |
11 |
Correct |
2 ms |
552 KB |
Output is correct |
12 |
Correct |
2 ms |
552 KB |
Output is correct |
13 |
Correct |
2 ms |
604 KB |
Output is correct |
14 |
Correct |
2 ms |
604 KB |
Output is correct |
15 |
Correct |
2 ms |
620 KB |
Output is correct |
16 |
Correct |
15 ms |
1204 KB |
Output is correct |
17 |
Correct |
16 ms |
1204 KB |
Output is correct |
18 |
Correct |
15 ms |
1204 KB |
Output is correct |
19 |
Correct |
15 ms |
1204 KB |
Output is correct |
20 |
Correct |
12 ms |
1204 KB |
Output is correct |
21 |
Correct |
58 ms |
2532 KB |
Output is correct |
22 |
Correct |
60 ms |
2564 KB |
Output is correct |
23 |
Correct |
59 ms |
2564 KB |
Output is correct |
24 |
Correct |
61 ms |
2672 KB |
Output is correct |
25 |
Correct |
61 ms |
2672 KB |
Output is correct |
26 |
Correct |
59 ms |
2672 KB |
Output is correct |
27 |
Correct |
58 ms |
2672 KB |
Output is correct |
28 |
Correct |
62 ms |
2672 KB |
Output is correct |
29 |
Correct |
61 ms |
2672 KB |
Output is correct |
30 |
Correct |
47 ms |
2672 KB |
Output is correct |
31 |
Correct |
1 ms |
2672 KB |
Output is correct |
32 |
Correct |
1 ms |
2672 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2672 KB |
Output is correct |
2 |
Correct |
1 ms |
2672 KB |
Output is correct |
3 |
Correct |
1 ms |
2672 KB |
Output is correct |
4 |
Correct |
1 ms |
2672 KB |
Output is correct |
5 |
Correct |
2 ms |
2672 KB |
Output is correct |
6 |
Correct |
2 ms |
2672 KB |
Output is correct |
7 |
Correct |
1 ms |
2672 KB |
Output is correct |
8 |
Correct |
1 ms |
2672 KB |
Output is correct |
9 |
Correct |
1 ms |
2672 KB |
Output is correct |
10 |
Correct |
1 ms |
2672 KB |
Output is correct |
11 |
Correct |
2 ms |
2672 KB |
Output is correct |
12 |
Correct |
3 ms |
2672 KB |
Output is correct |
13 |
Correct |
2 ms |
2672 KB |
Output is correct |
14 |
Correct |
2 ms |
2672 KB |
Output is correct |
15 |
Correct |
2 ms |
2672 KB |
Output is correct |
16 |
Correct |
19 ms |
2672 KB |
Output is correct |
17 |
Correct |
21 ms |
2672 KB |
Output is correct |
18 |
Correct |
20 ms |
2672 KB |
Output is correct |
19 |
Correct |
20 ms |
2672 KB |
Output is correct |
20 |
Correct |
9 ms |
2672 KB |
Output is correct |
21 |
Correct |
72 ms |
2672 KB |
Output is correct |
22 |
Correct |
73 ms |
2672 KB |
Output is correct |
23 |
Correct |
73 ms |
2672 KB |
Output is correct |
24 |
Correct |
74 ms |
2672 KB |
Output is correct |
25 |
Correct |
70 ms |
3580 KB |
Output is correct |
26 |
Correct |
73 ms |
3580 KB |
Output is correct |
27 |
Correct |
74 ms |
3580 KB |
Output is correct |
28 |
Correct |
73 ms |
3580 KB |
Output is correct |
29 |
Correct |
73 ms |
3580 KB |
Output is correct |
30 |
Correct |
45 ms |
3580 KB |
Output is correct |
31 |
Correct |
1 ms |
3580 KB |
Output is correct |
32 |
Correct |
2 ms |
3580 KB |
Output is correct |