Submission #933852

#TimeUsernameProblemLanguageResultExecution timeMemory
933852koukirocksLet's Win the Election (JOI22_ho_t3)C++17
21 / 100
462 ms8784 KiB
#include <bits/stdc++.h> #define speed ios_base::sync_with_stdio(0); cin.tie(0) #define all(x) (x).begin(),(x).end() using namespace std; typedef long long ll; typedef double db; typedef long double ldb; typedef pair<int,int> pii; typedef pair<ll,ll> pll; const ll MAX=5e2+10,P=998244353; const ll INF=0x3f3f3f3f,oo=0x3f3f3f3f3f3f3f3f; ll n,k; pair<ldb,ldb> vt[MAX]; ldb dp[MAX][MAX]; ldb suf[MAX][MAX]; int main() { speed; cin>>n>>k; for (int i=1;i<=n;i++) { cin>>vt[i].first>>vt[i].second; if (vt[i].second==-1) vt[i].second=oo; } sort(vt+1,vt+n+1,[=](pair<ldb,ldb> a,pair<ldb,ldb> b){ if (abs(a.second-b.second)<1e-6) return a.first>b.first; return a.second<b.second; }); for (int i=1;i<=k;i++) { suf[n+1][i]=oo; } suf[n+1][0]=0; for (int i=n;i>=1;i--) { suf[i][0]=0; for (int j=k;j>=1;j--) { suf[i][j]=min(suf[i+1][j-1]+vt[i].first,suf[i+1][j]); // cout<<i<<" "<<j<<" "<<suf[i][j]<<" suf\n"; } } ldb ans=suf[1][k]; for (int i=1;i<=k;i++) { for (int j=1;j<=n;j++) dp[0][j]=oo; dp[0][0]=0; for (int j=1;j<=k;j++) { for (int x=1;x<=n;x++) dp[j][x]=oo; dp[j][0]=dp[j-1][0]+vt[i].first/(i+1); for (int x=1;x<=i and x<=j;x++) { dp[j][x]=min(dp[j-1][x]+vt[j].first/(i+1),dp[j-1][x-1]+vt[j].second/x); // cout<<i<<" "<<j<<" "<<x<<" "<<dp[j-1][x]+vt[j].first/(i+1)<<" "<<dp[j-1][x-1]+vt[j].second/x<<"\n"; if (x==i) { ans=min(ans,dp[j][x]+suf[j+1][k-j]/(i+1)); // cout<<i<<" "<<j<<" "<<x<<" "<<dp[j][x]<<" "<<suf[j+1][k-j]/(i+1)<<"\n"; } } } } cout<<fixed<<setprecision(20)<<ans<<"\n"; return 0; }
#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...