제출 #1196121

#제출 시각아이디문제언어결과실행 시간메모리
1196121JuanJLLet's Win the Election (JOI22_ho_t3)C++20
23 / 100
2628 ms990704 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 

#define fst first 
#define snd second
#define pb push_back
#define forn(i,a,b) for(int i = a; i < b; i++)
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
#define mset(a,v) memset((a),(v),sizeof(a))
#define FIN ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define dbg(v) cout<<"Line("<<__LINE__<<"): "<<#v<<" = "<<v<<'\n';
#define pi pair<int,int>
#define pll pair<ll,ll>
typedef int ll;
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_multiset;

const int MAXN = 502;
double dp[MAXN][MAXN][MAXN];
bool vis[MAXN][MAXN][MAXN];
ll n,k,c;
vector<pair<double,double>> s; 

double f(ll x, ll y, ll z){
	
	double &res = dp[x][y][z];
	
	if(vis[x][y][z]) return res;
	vis[x][y][z]=true;
	
	if(y==k&&z==c){ return res=(double)0;}
	if(x==n) return res=(double)10000000000;
	if(n-x<k-y) return res=(double)10000000000;
	if(n-x<c-z) return res=(double)10000000000;
	
	
	
	res=f(x+1,y,z);
	res=min(res,f(x+1,y+1,z)+(s[x].snd/(c+1))); 	
	if(z<c){
		res=min(res,f(x+1,y+1,z+1)+(s[x].fst/(z+1)));
	}
		
	//cout<<x<<" "<<y<<" "<<z<<" ->>>> "<<res<<'\n';
	return res;
}

int main(){FIN;
	cin>>n>>k;
	
	s.clear();
	s.resize(n);
	
	forn(i,0,n){ cin>>s[i].snd>>s[i].fst; if(s[i].fst==-1){ s[i].fst=(double)10000000000000000; }}
	
	sort(ALL(s));
	//forn(i,0,n) cout<<s[i].fst<<" "<<s[i].snd<<'\n';

	double rres = (double)100000000;
	forn(cc,0,k+1){
		forn(i,0,MAXN){
			for(int j = MAXN-1; j>=0; j--){
				for(int h = MAXN-1; h>=0; h--){
					dp[i][j][h]=(double)1000000000;	
				}
			}
		}
		//cout<<"empieza"<<'\n';
		c=cc;
		forn(i,0,n+1) dp[i][k][cc]=0;
		for(int i = n-1; i>=0; i--){
			for(int j = k; j>=0; j--){
				for(int h = i; h>=0; h--){
					double &res = dp[i][j][h];
					res=dp[i+1][j][h];
					res=min(res,dp[i+1][j+1][h]+s[i].snd/(cc+1));
					if(h<cc) res=min(res,dp[i+1][j+1][h+1]+s[i].fst/(h+1));
					//cout<<i<<" "<<j<<" "<<h<<" ->>>>> "<<res<<'\n';
				}
			} 
		}
		rres=min(rres,dp[0][0][0]);
		//cout<<cc<<" "<<" -------------------- "<<dp[0][0][0]<<'\n';
	}
	
	//cout<<"llego\n";
	cout<<fixed<<setprecision(15)<<rres<<'\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...