제출 #532049

#제출 시각아이디문제언어결과실행 시간메모리
532049Haruto810198Let's Win the Election (JOI22_ho_t3)C++17
56 / 100
2574 ms976 KiB
#include <bits/stdc++.h>

using namespace std;

#define int long long
#define double long double

#define FOR(i, l, r, d) for(int i=(l); i<=(r); i+=(d))
#define szof(x) ((int)(x).size())

#define vi vector<int>
#define pii pair<int, int>

#define F first
#define S second

#define pb push_back
#define eb emplace_back
#define mkp make_pair

const int INF = INT_MAX;
const int LNF = INF*INF;
const int MOD = 1000000007;
const int mod = 998244353;
const double eps = 1e-12;

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")

const int MAX = 510;

struct State{
	double A, B;	
};

int n, k;
State state[MAX];
double res;

double dp[MAX][MAX];

bool cmp_by_B(State x, State y){
	if(x.B == y.B) return (x.A < y.A);
	return (x.B < y.B);
}

signed main(){
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	cin>>n>>k;
	FOR(i, 1, n, 1){
		cin>>state[i].A>>state[i].B;
		if(state[i].B == -1) state[i].B = INF;
	}
	sort(state+1, state+n+1, cmp_by_B);
	
	res = INF;
	// enum. n. of collaborators
	FOR(C, 0, k, 1){
		int V = k - C;
		// C collaborators, V votes
		
		FOR(i, 0, C, 1){
			FOR(j, 0, V, 1){
				dp[i][j] = INF;
			}
		}
		dp[0][0] = 0;

		FOR(x, 1, n, 1){
			for(int i = C; i >= 0; i--){
				for(int j = V; j >= 0; j--){
					if(i > 0) dp[i][j] = min(dp[i][j], dp[i-1][j] + state[x].B / i);
					if(j > 0) dp[i][j] = min(dp[i][j], dp[i][j-1] + state[x].A / (C+1));
				}
			}
		}

		res = min(res, dp[C][V]);
	}

	cout<<fixed<<setprecision(12)<<res<<'\n';
	
	return 0;

}
#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...