Submission #863892

# Submission time Handle Problem Language Result Execution time Memory
863892 2023-10-21T10:45:39 Z phoenix0423 Let's Win the Election (JOI22_ho_t3) C++17
0 / 100
160 ms 2396 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<double, double> pll;
#define fastio ios::sync_with_stdio(false), cin.tie(0)
#pragma GCC optimize("Ofast")
#define pb push_back
#define eb emplace_back
#define f first
#define s second
#define lowbit(x) x&-x
const int maxn = 2e5 + 5;
const double INF = 1e18;

//enumerate number of b from 0 ... k - 1
//it is optimal to get collaboraters first then give speeches to k - #b people
//for a set of collaboraters, it is optimal to sort them by increasing bs

double dp[505][505];

int main(void){
	fastio;
	int n, k;
	cin>>n>>k;
	vector<pll> a(n);
	for(int i = 0; i < n; i++){
		cin>>a[i].f>>a[i].s;
		if(a[i].s == -1) a[i].s = INF;
	}
	sort(a.begin(), a.end(), [&](pll a, pll b){ return a.s < b.s || (a.s == b.s && a.f < b.f);});
	auto f = [&](int goal) -> double {
		double best = INF;
		for(int i = 0; i <= n; i++) for(int j = 0; j <= goal; j++) dp[i][j] = INF;
		dp[0][0] = 0;
		for(int i = 0; i < n; i++){
			for(int j = 0; j < goal; j++){
				dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + a[i].f / (goal + 1));
				dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j] + a[i].s / (j + 1));
			}
		}
		for(int i = 0; i <= n; i++){
			//choose k - i elements for second set
			vector<double> cand;
			for(int j = i; j < n; j++) cand.pb(a[j].f);
			sort(cand.begin(), cand.end());
			double cur = dp[i][goal];
			for(int j = 0; j < k - i; j++) cur += cand[j] / (goal + 1);
			best = min(best, cur);
		}
		return best;
	};
	int l = 0, r = k;
	while(r - l >= 3){
		int m1 = l + (r - l) / 3, m2 = r - (r - l) / 3;
		double c1 = f(m1), c2 = f(m2);
		if(c1 > c2) r = m2;
		else l = m1;
	}
	double best = INF;
	for(int i = l; i <= r; i++) best = min(best, f(i));
	cout<<fixed<<setprecision(5)<<best<<"\n";
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 1 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 1 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 344 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 344 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 344 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 160 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 1 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -