Submission #733442

#TimeUsernameProblemLanguageResultExecution timeMemory
733442shoryu386Let's Win the Election (JOI22_ho_t3)C++17
10 / 100
511 ms988640 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define db double

#define MAX 502
db dp[MAX][MAX][MAX];
int n, k;

pair<db, db> info[MAX];

bool cmp(pair<db, db> a, pair<db, db> b){
	if (a.second == -1) a.second = 1000000000;
	if (b.second == -1) b.second = 1000000000;
	
	return a.second > b.second;
	
}

db recur(int idx, int colabCount, int voteCount){
	if (idx == n && voteCount >= k) return 0;
	else if (idx == n) return 1000000000;
	
	if (dp[idx][colabCount][voteCount] != -1) return dp[idx][colabCount][voteCount];
	if (info[idx].second == -1) return dp[idx][colabCount][voteCount] = min(recur(idx+1, colabCount, voteCount), recur(idx+1, colabCount, voteCount+1) + info[idx].first/colabCount);
	return dp[idx][colabCount][voteCount] = min({recur(idx+1, colabCount, voteCount), recur(idx+1, colabCount, voteCount+1) + info[idx].first/colabCount, recur(idx+1, colabCount+1, voteCount+1) + info[idx].second/colabCount});
}

main(){

	cin >> n >> k;
	
	for (int x = 0; x < n; x++) cin >> info[x].first >> info[x].second;
	
	sort(info, info+n);
	
	//for (int x = 0; x < n; x++) cout << info[x].first << ' ' << info[x].second << '\n';

	
	for (int x = 0; x <= n; x++) for (int y = 0; y <= n+1; y++) for (int z = 0; z <= n; z++) dp[x][y][z] = -1;
	
	db ans = 1000000000000000LL;
	for (int x = 0; x <= n; x++){
		
		//make use of x colabs
		//initial sort is optimal for 0 colabs
		
		vector<pair<db, db>> colabSect;
		vector<pair<db, db>> voteSect;
		
		//wait is dp even needed
		
		for (int y = 0; y < n; y++) voteSect.push_back(info[y]);
		
		sort(voteSect.begin(), voteSect.end(), cmp); //give cheapest
		
		for (int y = 0; y < x; y++){
			colabSect.push_back(voteSect.back()); voteSect.pop_back();
		}
		
		if (colabSect.size() != 0 && colabSect.back().second == -1) break;
		
		sort(voteSect.begin(), voteSect.end()); //return to cheapest votes
		
		int votesNeeded = max(k - (int)colabSect.size(), 0LL);
		int colabCount = 1;
		db curAns = 0;
		for (auto y : colabSect){
			curAns += y.second/colabCount; colabCount++;
		}
		
		for (int y = 0; y < votesNeeded; y++){
			curAns += voteSect[y].first/colabCount;
		}
		
		ans = min(curAns, ans);
	}
	cout << std::setprecision(9) << ans;
}

Compilation message (stderr)

Main.cpp:30:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   30 | main(){
      | ^~~~
#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...