This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <int, pii> pip;
typedef pair <pii, int> ppi;
typedef pair <double, double> pdd;
const int INF=0x3f3f3f3f;
const int N=3005;
int n, k;
vector <pdd> hull[N];
int ind[N];
double ccw(pdd a, pdd b, pdd c) {
return a.X*(b.Y-c.Y)+b.X*(c.Y-a.Y)+c.X*(a.Y-b.Y);
}
double f(pdd pp, double x) {
return pp.X*x+pp.Y;
}
void dodaj(int i, pdd pp) {
while (hull[i].size()>1 && ccw(hull[i][(int)hull[i].size()-2], hull[i].back(), pp)>=0) hull[i].pop_back();
hull[i].pb(pp);
ind[i]=min(ind[i], (int)hull[i].size()-1);
}
double query(int i, double x) {
while (ind[i]<(int)hull[i].size()-1 && f(hull[i][ind[i]], x)<f(hull[i][ind[i]+1], x)) ++ind[i];
return f(hull[i][ind[i]], x);
}
int main() {
scanf("%d %d", &n, &k);
for (int i=0; i<=k; ++i) hull[i].pb(mp(1/(double)n, 0));
double sol=-1;
for (int i=1; i<=n; ++i) {
for (int j=k; j>=1; --j) {
double curr=query(j-1, i);
dodaj(j, mp(1.0/(double)(n-i), curr-(double)i/(n-i)));
if (i==n && j==k) sol=curr;
// printf("i: %d, j: %d, dp: %.7f\n", i, j, curr);
}
}
printf("%.10f\n", sol);
return 0;
}
Compilation message (stderr)
akvizna.cpp: In function 'int main()':
akvizna.cpp:42:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &n, &k);
~~~~~^~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |