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>
#define optimizar_io ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);cout.setf(ios::fixed);cout.precision(15);
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
#define x first
#define y second
pair<double,double> cad[501];
double sol(ll l,ll n,ll m)
{
vector<vector<vector<double>>> dp(2,vector<vector<double>>(m+3,vector<double>(m+3,1e9)));
dp[0][1][1]=0;
double bs=1e9;
for(int i=1; i<=n; i++)
{
for(int j=1; j<=m+1; j++)
{
for(int k=1; k<=m+1; k++)
{
double temp=1e9;
temp=min(temp,dp[0][j][k]);
temp=min(temp,dp[0][j][k-1]+cad[i].y/l);
if(cad[i].first!=-1&&j!=1)
temp=min(temp,dp[0][j-1][k-1]+cad[i].x/(j-1));
dp[1][j][k]=temp;
if(k==m+1&&j==l) bs=min(bs,dp[1][j][k]);
}
//cout<<"\n";
}
swap(dp[0],dp[1]);
//cout<<"\n\n";
}
return bs;
}
int main()
{
optimizar_io
ll n,m;
cin>>n>>m;
cad[0]={-1,-1};
for(int i=1; i<=n; i++)
cin>>cad[i].second>>cad[i].first;
sort(cad,cad+n+1);
double bs=1e9;
double lo = 0, hi = m+1;
for (int i = 0; i < 9; ++i) {
double delta = (hi-lo)/3.0;
double m1 = lo+delta;
double m2 = hi-delta;
double f1=sol(m1,n,m);
double f2=sol(m2,n,m);
bs=min(bs,f1);
bs=min(bs,f2);
(f1 > f2) ? lo = m1 : hi = m2;
}
cout<<bs;
}
# | 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... |