#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using flt=double;
int main() {
ios::sync_with_stdio(0);cin.tie(0);
int N, K;
cin>>N>>K;
flt l=0, r=2;
vector<int> C(N+1), P(N+1);
cout<<fixed<<setprecision(9);
auto f=[&](flt m) {
vector<double> D(N+1);
vector<int> T(1<<32-__builtin_clz(N));
auto f=[&](int j, int i) {
return D[j]+flt(i-j)/i;
};
auto cmp=[&](int i, int j, int x) {
return f(i, x)>f(j, x);
};
auto add=[&](int a) {
int s=1, e=N, i=1;
while(i) {
int m=s+e>>1, &b=T[i];
if(cmp(a, b, m)) swap(a, b);
if(cmp(a, b, s)) e=m-1, i=i*2;
else if(cmp(a, b, e)) s=m+1, i=i*2+1;
else break;
}
};
auto get=[&](int x) {
int s=1, e=N, i=1, a=0;
while(i) {
int m=s+e>>1, b=T[i];
if(cmp(b, a, x)) a=b;
if(x<m) e=m-1, i=i*2;
else if(x>m) s=m+1, i=i*2+1;
else break;
}
return a;
};
D[0]=0;
for(int i=1; i<=N; i++) {
add(i-1);
int p=get(i);
P[i]=p;
C[i]=C[p]+1;
D[i]=f(p, i)-m;
}
return make_pair(C[N], D[N]+K*m);
};
while(r-l>1e-12) {
flt m=(l+r)/2;
auto[k,x]=f(m);
if(k<K) r=m;
else if(k>K) l=m;
else { l=r=m; break; }
}
cout<<fixed<<setprecision(9)<<f((l+r)/2).second;
}
Compilation message
akvizna.cpp: In lambda function:
akvizna.cpp:15:22: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
15 | vector<int> T(1<<32-__builtin_clz(N));
| ~~^~~~~~~~~~~~~~~~~
akvizna.cpp: In lambda function:
akvizna.cpp:25:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
25 | int m=s+e>>1, &b=T[i];
| ~^~
akvizna.cpp: In lambda function:
akvizna.cpp:35:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
35 | int m=s+e>>1, b=T[i];
| ~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
384 KB |
Output is correct |
2 |
Correct |
28 ms |
512 KB |
Output is correct |
3 |
Correct |
23 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
384 KB |
Output is correct |
2 |
Correct |
17 ms |
384 KB |
Output is correct |
3 |
Correct |
21 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
388 KB |
Output is correct |
2 |
Correct |
17 ms |
384 KB |
Output is correct |
3 |
Correct |
20 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
384 KB |
Output is correct |
2 |
Correct |
20 ms |
384 KB |
Output is correct |
3 |
Correct |
23 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
512 KB |
Output is correct |
2 |
Correct |
21 ms |
384 KB |
Output is correct |
3 |
Correct |
21 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
384 KB |
Output is correct |
2 |
Correct |
24 ms |
384 KB |
Output is correct |
3 |
Correct |
24 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
384 KB |
Output is correct |
2 |
Correct |
20 ms |
384 KB |
Output is correct |
3 |
Correct |
30 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
384 KB |
Output is correct |
2 |
Correct |
19 ms |
384 KB |
Output is correct |
3 |
Correct |
23 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
384 KB |
Output is correct |
2 |
Correct |
28 ms |
384 KB |
Output is correct |
3 |
Correct |
21 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1154 ms |
2360 KB |
Output is correct |
2 |
Correct |
1238 ms |
2408 KB |
Output is correct |
3 |
Correct |
1197 ms |
2348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1163 ms |
2336 KB |
Output is correct |
2 |
Correct |
1282 ms |
2432 KB |
Output is correct |
3 |
Correct |
1244 ms |
2436 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1126 ms |
2368 KB |
Output is correct |
2 |
Correct |
1300 ms |
2588 KB |
Output is correct |
3 |
Correct |
1348 ms |
2456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1208 ms |
2416 KB |
Output is correct |
2 |
Correct |
1274 ms |
2596 KB |
Output is correct |
3 |
Correct |
1214 ms |
2448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1092 ms |
2464 KB |
Output is correct |
2 |
Correct |
1283 ms |
2472 KB |
Output is correct |
3 |
Correct |
1209 ms |
2452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1239 ms |
2536 KB |
Output is correct |
2 |
Correct |
1243 ms |
2444 KB |
Output is correct |
3 |
Correct |
1221 ms |
2332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1176 ms |
2556 KB |
Output is correct |
2 |
Correct |
1183 ms |
2340 KB |
Output is correct |
3 |
Correct |
1184 ms |
2460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1082 ms |
2452 KB |
Output is correct |
2 |
Correct |
1274 ms |
2536 KB |
Output is correct |
3 |
Correct |
1181 ms |
2468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1154 ms |
2464 KB |
Output is correct |
2 |
Correct |
1272 ms |
2556 KB |
Output is correct |
3 |
Correct |
1300 ms |
2468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1198 ms |
2432 KB |
Output is correct |
2 |
Correct |
1226 ms |
2396 KB |
Output is correct |
3 |
Correct |
1262 ms |
2544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1196 ms |
2480 KB |
Output is correct |
2 |
Correct |
1297 ms |
2532 KB |
Output is correct |
3 |
Correct |
1286 ms |
2528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1095 ms |
2480 KB |
Output is correct |
2 |
Correct |
1299 ms |
2476 KB |
Output is correct |
3 |
Correct |
1292 ms |
2432 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1248 ms |
2528 KB |
Output is correct |
2 |
Correct |
1284 ms |
2472 KB |
Output is correct |
3 |
Correct |
1285 ms |
2476 KB |
Output is correct |