#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define all(a) a.begin(),a.end()
#define println printf("\n");
#define readln(x) getline(cin,x);
#define pb push_back
#define endl "\n"
#define INT_INF 0x3f3f3f3f
#define LL_INF 0x3f3f3f3f3f3f3f3f
#define MOD 1000000007
#define MOD2 1190492669
#define SEED 131
#define mp make_pair
#define fastio cin.tie(0); cin.sync_with_stdio(0);
#define MAXN 100005
#define MAXV 100005
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef unordered_map<int,int> umii;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef pair<int,pii> triple;
typedef int8_t byte;
mt19937 g1(time(0));
int randint(int a, int b){return uniform_int_distribution<int>(a, b)(g1);}
ll randlong(ll a,ll b){return uniform_int_distribution<long long>(a, b)(g1);}
ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll fpow(ll b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}
struct node{
int l,r;
pair<int,pair<ld,ld>> bst;
};
struct MaxLiChaoTree{
node seg[4*MAXV];
inline ld calc(int rt, int m){return seg[rt].bst.second.first*m+seg[rt].bst.second.second;}
inline ld calc(pair<ld,ld> bst, int m){return bst.first*m+bst.second;}
inline ld inter(pair<ld,ld> f, pair<ld,ld> s){return (s.second-f.second)/(f.first-s.first);}
void build(int l, int r, int rt){
seg[rt].l = l, seg[rt].r = r, seg[rt].bst = mp(-1,mp(0,-LL_INF));
if(l == r) return;
int mid = (l+r)/2;
build(l,mid,rt<<1);
build(mid+1,r,rt<<1|1);
}
void add_line(int rt, pair<int,pair<ld,ld>> line){
if(seg[rt].l == seg[rt].r){
if(calc(line.second,seg[rt].l) >= calc(rt,seg[rt].l)) seg[rt].bst = line;
return;
}
int mid = (seg[rt].l+seg[rt].r)/2;
bool f = calc(rt,seg[rt].l) <= calc(line.second,seg[rt].l);
bool s = calc(rt,seg[rt].r) <= calc(line.second,seg[rt].r);
if(f && s){
seg[rt].bst = line;
return;
}else if(!f && !s) return;
ld x = inter(line.second,seg[rt].bst.second);
if(x <= mid){
if(calc(line.second,mid) >= calc(rt,mid)) swap(line,seg[rt].bst);
add_line(rt<<1,line);
}else{
if(calc(line.second,mid) >= calc(rt,mid)) swap(line,seg[rt].bst);
add_line(rt<<1|1,line);
}
}
pair<ld,int> get(int rt, int pos){
if(seg[rt].l == seg[rt].r) return mp(calc(rt,pos),seg[rt].bst.first);
int mid = (seg[rt].l+seg[rt].r)/2;
if(pos <= mid) return max(mp(calc(rt,pos),seg[rt].bst.first),get(rt<<1,pos));
return max(mp(calc(rt,pos),seg[rt].bst.first),get(rt<<1|1,pos));
}
};
int N,K;
//double dp2[MAXN][MAXN];
pair<ld,int> dp[MAXN];
MaxLiChaoTree t;
inline double inter(int j, int k){
double m1 = dp[j].first, b1 = -j;
double m2 = dp[k].first, b2 = -k;
return (b2-b1)/(m1-m2);
}
inline int getGroups(double C){
// deque<int> dq; dq.pb(0);
t.build(1,N,1); t.add_line(1,mp(0,mp(0,0)));
for(int i=1; i<=N; i++){
// while(dq.size() >= 2 && dp[dq[0]].first*i-dq[0] <= dp[dq[1]].first*i-dq[1]) dq.pop_front();
pair<ld,int> p = t.get(1,i);
dp[i].first = p.first/i+1-C;
dp[i].second = dp[p.second].second+1;
// while(dq.size() >= 2 && inter(dq[dq.size()-2],i) <= inter(dq[dq.size()-2],dq.back())) dq.pop_back();
// dq.pb(i);
t.add_line(1,mp(i,mp(dp[i].first,-i)));
}
return dp[N].second;
}
//inline double solve(){
// for(int k=1; k<=K; k++){
// deque<int> dq; dq.pb(0);
// for(int i=1; i<=N; i++){
// while(dq.size() >= 2 && dp2[k-1][dq[0]]*i-dq[0] <= dp2[k-1][dq[1]]*i-dq[1]) dq.pop_front();
// dp2[k][i] = (dp2[k-1][dq[0]]*i-dq[0])/i+1;
// while(dq.size() >= 2 && inter(k,dq[dq.size()-2],i) <= inter(k,dq[dq.size()-2],dq.back())) dq.pop_back();
// dq.pb(i);
// }
// }
// return dp2[K][N];
//}
int main(){
scanf("%d %d",&N,&K);
double low = 0, high = 20, ans = 0;
while(high-low >= 1e-15){
double mid = (low+high)/2;
int g = getGroups(mid);
if(g <= K){
ans = mid;
high = mid-1e-15;
}else low = mid+1e-15;
}
getGroups(ans);
ld res = dp[N].first+ans*K;
printf("%.8Lf\n",res);
}
/*
2 1
ans=1.5
*/
Compilation message
akvizna.cpp: In function 'int main()':
akvizna.cpp:134:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d",&N,&K);
~~~~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
25336 KB |
Output is correct |
2 |
Correct |
25 ms |
25336 KB |
Output is correct |
3 |
Correct |
25 ms |
25336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
25336 KB |
Output is correct |
2 |
Correct |
25 ms |
25336 KB |
Output is correct |
3 |
Correct |
25 ms |
25336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
25464 KB |
Output is correct |
2 |
Correct |
25 ms |
25336 KB |
Output is correct |
3 |
Correct |
25 ms |
25336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
25340 KB |
Output is correct |
2 |
Correct |
25 ms |
25336 KB |
Output is correct |
3 |
Correct |
25 ms |
25336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
84 ms |
25564 KB |
Output is correct |
2 |
Correct |
91 ms |
25544 KB |
Output is correct |
3 |
Correct |
85 ms |
25464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
88 ms |
25592 KB |
Output is correct |
2 |
Correct |
90 ms |
25464 KB |
Output is correct |
3 |
Correct |
86 ms |
25464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
86 ms |
25508 KB |
Output is correct |
2 |
Correct |
86 ms |
25464 KB |
Output is correct |
3 |
Correct |
82 ms |
25464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
91 ms |
25464 KB |
Output is correct |
2 |
Correct |
91 ms |
25436 KB |
Output is correct |
3 |
Correct |
85 ms |
25540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
85 ms |
25464 KB |
Output is correct |
2 |
Correct |
90 ms |
25464 KB |
Output is correct |
3 |
Correct |
83 ms |
25464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
80 ms |
25464 KB |
Output is correct |
2 |
Correct |
91 ms |
25464 KB |
Output is correct |
3 |
Correct |
89 ms |
25464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
88 ms |
25464 KB |
Output is correct |
2 |
Correct |
91 ms |
25468 KB |
Output is correct |
3 |
Correct |
89 ms |
25504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
85 ms |
25508 KB |
Output is correct |
2 |
Correct |
88 ms |
25516 KB |
Output is correct |
3 |
Correct |
86 ms |
25464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
89 ms |
25464 KB |
Output is correct |
2 |
Correct |
87 ms |
25592 KB |
Output is correct |
3 |
Correct |
87 ms |
25556 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1568 ms |
28296 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1557 ms |
28280 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1562 ms |
28536 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1570 ms |
28408 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1568 ms |
28408 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1579 ms |
28408 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1562 ms |
28408 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1574 ms |
28284 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1569 ms |
28408 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1572 ms |
28408 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1570 ms |
28540 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1561 ms |
28536 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1568 ms |
28568 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |