Submission #638726

#TimeUsernameProblemLanguageResultExecution timeMemory
638726jamezzzLet's Win the Election (JOI22_ho_t3)C++17
61 / 100
2572 ms4296 KiB
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define sf scanf
#define pf printf
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
 
#define maxn 505
#define INF 1023456789
 
int n,k,a[maxn],b[maxn];
vector<ii> v;
ld memo[maxn][maxn];
 
int main(){
	sf("%d%d",&n,&k);
	for(int i=0;i<n;++i){
		int x,y;
		sf("%d%d",&x,&y);
		if(y==-1)y=INF;
		v.push_back({x,y});
	}
	sort(v.begin(),v.end(),[](ii &a,ii &b){
		if(a.se==b.se)return a.fi>b.fi;
		else return a.se<b.se;
	});
	int cnt=0;
	for(int i=0;i<n;++i){
		tie(a[i],b[i])=v[i];
		if(b[i]!=INF)++cnt;
	}
	ld ans=INF;
	for(int take=0;take<=cnt;++take){
		for(int i=0;i<=n+1;++i){
			for(int j=0;j<=n+1;++j){
				memo[i][j]=INF;
			}
		}
		memo[0][0]=0;
		for(int pos=0;pos<n;++pos){
			for(int ppl=take;ppl>=0;--ppl){
				for(int vote=pos+1;vote>=0;--vote){
					ld ans=memo[ppl][vote];
					if(vote!=0)ans=min(ans,memo[ppl][vote-1]+(ld)a[pos]/(take+1));
					if(vote!=0&&ppl!=0&&b[pos]!=INF){
						ans=min(ans,memo[ppl-1][vote-1]+(ld)b[pos]/ppl);
					}
					memo[ppl][vote]=ans;
				}
			}
		}
		ans=min(ans,memo[take][k]);
	}
	pf("%.15Lf\n",ans);
}

/*
7
5
393 646
375 666
374 676
320 635
288 668
284 758
333 702

1258.500000000000000
*/

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:20:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |  sf("%d%d",&n,&k);
      |    ^
Main.cpp:23:5: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |   sf("%d%d",&x,&y);
      |     ^
#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...