Submission #891889

#TimeUsernameProblemLanguageResultExecution timeMemory
8918898pete8Let's Win the Election (JOI22_ho_t3)C++17
100 / 100
907 ms8028 KiB
#include<iostream> #include<stack> #include<map> #include<vector> #include<string> #include<unordered_map> #include <queue> #include<cstring> #include<float.h> #include<limits.h> #include <cassert> #include<cmath> #include<set> #include<algorithm> #include <iomanip> #include<numeric> //gcd(a,b) #include<bitset> using namespace std; #define ll long long #define f first #define endl "\n" #define s second #define pii pair<int,int> #define ppii pair<pii,int> #define vi vector<int> #define pb push_back #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define F(n) for(int i=0;i<n;i++) #define lb lower_bound #define ub upper_bound #define fastio ios::sync_with_stdio(false);cin.tie(NULL); #pragma GCC optimize ("03,unroll-loops") using namespace std; #define int long long #define double long double const int mod=998244353,mxn=2e5+5,lg=30,inf=1e9,minf=-1e9,Mxn=100000; //bool use[mxn+10]; double dp[600][600]; int32_t main(){ fastio int n,k;cin>>n>>k; double ans=inf; vector<pii>v(n); for(int i=0;i<n;i++){ cin>>v[i].f>>v[i].s; v[i].s=(v[i].s==-1)?inf:v[i].s; swap(v[i].s,v[i].f); } sort(all(v)); vector<vector<int>>sum(600,vector<int>(600,inf)); for(int i=0;i<=n;i++)sum[i][0]=0; for(int i=n-1;i>=0;i--)for(int j=k;j>=1;j--)sum[i][j]=min(sum[i+1][j],sum[i+1][j-1]+v[i].s); ans=min(ans,(double)sum[0][k]); for(int use=1;use<=k;use++){ 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=0;j<k;j++){ for(int g=0;g<use;g++){ dp[j+1][g]=min(dp[j][g]+(v[j].s*1.0/use),dp[j+1][g]); if(v[j].f!=inf)dp[j+1][g+1]=min(dp[j+1][g+1],dp[j][g]+(v[j].f*1.0/(g+1))); } ans=min(ans,dp[j+1][use-1]+sum[j+1][k-j-1]*1.0/use); } } cout<<setprecision(12); cout<<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...