Submission #965702

#TimeUsernameProblemLanguageResultExecution timeMemory
96570212345678Let's Win the Election (JOI22_ho_t3)C++17
100 / 100
155 ms4444 KiB
#include <bits/stdc++.h> using namespace std; const int nx=505; int n, m; vector<pair<int, int>> v(nx); double dp[nx][nx], sm[nx][nx], ans; int32_t main() { cin.tie(NULL)->sync_with_stdio(false); cin>>n>>m; v.resize(n); for (int i=0; i<n; i++) { cin>>v[i].second>>v[i].first; if (v[i].first==-1) v[i].first=1e9; } sort(v.begin(), v.end()); for (int i=1; i<=m; i++) sm[n+1][i]=1e9; for (int i=n;i>=1; i--) for (int j=1; j<=m; j++) sm[i][j]=min(sm[i+1][j], sm[i+1][j-1]+v[i-1].second); //cout<<"sm "<<i<<' '<<j<<' '<<sm[i][j]<<'\n'; ans=sm[1][m]; for (int i=1; i<=m; i++) { for (int j=0; j<=m; j++) for (int k=0; k<=i; k++) dp[j][k]=1e9; dp[0][1]=0; for (int j=1; j<=m; j++) { for (int k=1; k<=i; k++) { dp[j][k]=dp[j-1][k]+(double)v[j-1].second/i; if (k>1&&v[j-1].first<=1000) dp[j][k]=min(dp[j][k], dp[j-1][k-1]+((double)v[j-1].first)/(k-1)); //cout<<"debug "<<i<<' '<<j<<' '<<k<<' '<<dp[j][k]<<'\n'; } ans=min(ans, dp[j][i]+sm[j+1][m-j]/i); //cout<<i<<' '<<j<<' '<<dp[j][i]+sm[j+1][m-j]/i<<'\n'; } } cout<<fixed<<setprecision(12)<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...