제출 #1224781

#제출 시각아이디문제언어결과실행 시간메모리
1224781ByeWorldLet's Win the Election (JOI22_ho_t3)C++20
100 / 100
975 ms6232 KiB
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
// #define int long long
#define ll long long
#define fi first
#define se second
#define lf ((id<<1))
#define rg ((id<<1)|1)
#define md ((l+r)>>1)
#define pb push_back
#define ld double
using namespace std;
const int MAXN = 2e5+10;
const ld INF = 1e9+10;
typedef pair<int,int> pii;
void chmn(auto &a, auto b){ a = min(a, b); }

int n, k;
int p[MAXN], q[MAXN], a[MAXN], b[MAXN];
ld ans = INF;
ld dp[3][510][510];

ld coba(int col){
	for(int i=0; i<=2; i++) 
		for(int take=0; take<=col; take++) // ambil b
			for(int oth=0; oth<=k-col; oth++) // ambil a
				dp[i][take][oth] = INF;

	dp[0][0][0] = 0;
	for(int i=1; i<=n; i++){
		for(int take=0; take<=col; take++){
			for(int oth=0; oth<=k-col; oth++){
				// gk ambil samsek
				dp[i%2][take][oth] = dp[(i-1)%2][take][oth];
				// ambil a
				if(oth>=1)
					dp[i%2][take][oth] = min(dp[i%2][take][oth],
						dp[(i-1)%2][take][oth-1] + (ld)a[i]/(col+1)); 
				// ambil b
				if(take>=1)
					dp[i%2][take][oth] = min(dp[i%2][take][oth],
						dp[(i-1)%2][take-1][oth] + (ld)b[i]/take );
			}
		}
	}
	// cout << col << ' ' << dp[n][col] << " pp\n";
	return dp[n%2][col][k-col];
}
signed main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>k;
	vector<pii> vec;
	vec.pb({-1,-1});
	for(int i=1; i<=n; i++){
		cin>>p[i]>>q[i];
		if(q[i] == -1) q[i] = MAXN;
		vec.pb({q[i], i});
	}
	sort(vec.begin(), vec.end());
	for(int i=1; i<=n; i++)
		a[i] = p[vec[i].se], b[i] = q[vec[i].se];

	int l = 0, r = k-1, cnt = -1;
	while(l<=r){
		int mid = (l+r)>>1;
		if(coba(mid) <= coba(mid+1)) cnt = mid, r = mid-1;
		else l = mid+1;
	}

	cout << fixed << setprecision(7) << coba(cnt) << '\n';
}
#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...