Submission #933867

#TimeUsernameProblemLanguageResultExecution timeMemory
933867koukirocksLet's Win the Election (JOI22_ho_t3)C++17
100 / 100
1121 ms8792 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=INF; } sort(vt+1,vt+n+1,[=](pair<ldb,ldb> a,pair<ldb,ldb> b){ return a.second<b.second; }); for (int i=1;i<=k;i++) { suf[n+1][i]=INF; } 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 i=0;i<=n;i++) { for (int j=0;j<=n;j++) dp[i][j]=INF; } dp[0][0]=0; for (int j=1;j<=k;j++) { for (int x=0;x<=i;x++) { dp[j][x]=min(dp[j][x],dp[j-1][x]+vt[j].first/(i+1)); if (x!=0) dp[j][x]=min(dp[j][x],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...