답안 #532682

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
532682 2022-03-03T15:40:39 Z victor_gao Let's Win the Election (JOI22_ho_t3) C++17
0 / 100
2500 ms 332 KB
//#pragma GCC optimize("Ofast,unroll-loops,O3")
//#pragma GCC target("avx,avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,fma,tune=native")
#include<bits/stdc++.h>
//#include<bits/extc++.h>
//#pragma pack(1)
#define fast ios::sync_with_stdio(0); cin.tie(0);
#define int long long
#define pii pair<int,int>
#define x first
#define y second
#define N 515
using namespace std;
//using namespace __gnu_pbds;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//typedef tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> order_multiset;
//typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> order_set;
int n,k,a[N],b[N];
long double dp[N],ans=1e100;
bool vis[N];
vector<pii>tog,need;
void solve(int val){
	tog.clear();
	need.clear();
	memset(vis,0,sizeof(vis));
	for (int i=0;i<n;i++){
		if (val&(1LL<<i)){
			need.push_back({a[i],i});
			if (b[i]!=-1){
				tog.push_back({b[i],i});
			}
//			cout<<1;
		}
//		cout<<0;
	}
//	cout<<'\n';
	sort(need.begin(),need.end());
	sort(tog.begin(),tog.end());
	for (int i=0;i<=tog.size();i++){
		dp[i]=0;
		int need_time=0,cnt=0;
		for (int j=0;j<i&&j<tog.size();j++){
			dp[i]+=((long double)(tog[j].x)/(j+1));
			vis[tog[j].y]=1;
		}
		for (auto j:need){
			if (!vis[j.y]){
				cnt++;
				need_time+=j.x;
			}
			if (cnt>=k-i) break;
		}
		dp[i]+=(long double)need_time/(i+1);
	}
	long double tans=1e100;
	for (int i=0;i<=tog.size();i++){
		tans=min(tans,dp[i]);
	}
//	cout<<" -> "<<tans<<'\n';
	ans=min(ans,tans);
}
signed main(){
	fast
	cout<<fixed<<setprecision(20);
	cin>>n>>k;
	for (int i=0;i<n;i++){
		cin>>a[i]>>b[i];
	}
	for (int i=1;i<(1LL<<n);i++){
		int cnt=0;
		for (int j=0;j<n;j++){
			if (i&(1LL<<j)) cnt++;
		}
		if (cnt==k) solve(i);
	}
	cout<<ans<<'\n';
}

Compilation message

Main.cpp: In function 'void solve(long long int)':
Main.cpp:38:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |  for (int i=0;i<=tog.size();i++){
      |               ~^~~~~~~~~~~~
Main.cpp:41:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |   for (int j=0;j<i&&j<tog.size();j++){
      |                     ~^~~~~~~~~~~
Main.cpp:55:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |  for (int i=0;i<=tog.size();i++){
      |               ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Execution timed out 2563 ms 332 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Execution timed out 2563 ms 332 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Incorrect 1 ms 324 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Incorrect 1 ms 324 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Incorrect 1 ms 324 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2543 ms 328 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Execution timed out 2563 ms 332 KB Time limit exceeded
6 Halted 0 ms 0 KB -