Submission #733451

# Submission time Handle Problem Language Result Execution time Memory
733451 2023-04-30T18:37:12 Z shoryu386 Let's Win the Election (JOI22_ho_t3) C++17
0 / 100
356 ms 36492 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define db long double

#define MAX 102
db dp[MAX][MAX][MAX];
int n, k;
 
pair<db, db> info[MAX];

vector<pair<db, db>> cringe;
 
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 (cringe[idx].second == -1) return dp[idx][colabCount][voteCount] = min(recur(idx+1, colabCount, voteCount), recur(idx+1, colabCount, voteCount+1) + cringe[idx].first/colabCount);
	return dp[idx][colabCount][voteCount] = min({recur(idx+1, colabCount, voteCount), recur(idx+1, colabCount, voteCount+1) + cringe[idx].first/colabCount, recur(idx+1, colabCount+1, voteCount+1) + cringe[idx].second/colabCount});
}

bool anticmp(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;
	
}

signed main(){

	cin >> n >> k;
	
	for (int x = 0; x < n; x++) cin >> info[x].first >> info[x].second;
	
	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(), anticmp); //give cheapest
		
		//find which to use as colab
		
		
		for (int y = 0; y < x; y++){
			colabSect.push_back(voteSect.back()); 
			
			//cout << voteSect.back().first << ' ' << voteSect.back().second << '\n';
			
			voteSect.pop_back();
			
		}
		//cout << '\n' << '\n';
		
		sort(voteSect.begin(), voteSect.end()); //return to cheapest votes
		
		cringe.clear();
		for (auto x : colabSect) cringe.push_back(x);
		for (auto x : voteSect) cringe.push_back(x);
		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;
		
		ans = min(ans, recur(0, 1, 0));
	}
	cout << std::setprecision(9) << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Runtime error 338 ms 36492 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Runtime error 338 ms 36492 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Incorrect 0 ms 340 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Incorrect 0 ms 340 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Incorrect 0 ms 340 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 356 ms 36376 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Runtime error 338 ms 36492 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -