Submission #533061

# Submission time Handle Problem Language Result Execution time Memory
533061 2022-03-04T15:15:25 Z victor_gao Let's Win the Election (JOI22_ho_t3) C++17
23 / 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,all;
void solve(){
	sort(tog.begin(),tog.end());
	for (int i=0;i<=n;i++) vis[i]=0;
	long double tans=0;
	for (int i=0;i<tog.size();i++){
		tans+=(long double)tog[i].x/(long double)(i+1);
		vis[tog[i].y]=1;
	}
	int need=k-tog.size(),total=0;
	for (int i=1;i<=n&&need;i++){
		if (!vis[all[i-1].y]){
			need--;
			total+=all[i-1].x;
		}
	}
	tans+=(long double)total/(long double)(tog.size()+1);
//	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];
		all.push_back({a[i],i});
	}
	sort(all.begin(),all.end());
	for (int i=0;i<(1LL<<n);i++){
		tog.clear();
		for (int j=0;j<n;j++){
			if (i&(1LL<<j)){
				if (b[j]!=-1) tog.push_back({b[j],j}); 
			}
		}
		if (tog.size()<=k) solve();
	}
	cout<<ans<<'\n';
}

Compilation message

Main.cpp: In function 'void solve()':
Main.cpp:25: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]
   25 |  for (int i=0;i<tog.size();i++){
      |               ~^~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:56:17: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   56 |   if (tog.size()<=k) solve();
      |       ~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Execution timed out 2597 ms 332 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Execution timed out 2597 ms 332 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 103 ms 312 KB Output is correct
17 Correct 133 ms 332 KB Output is correct
18 Correct 141 ms 204 KB Output is correct
19 Correct 223 ms 308 KB Output is correct
20 Correct 215 ms 324 KB Output is correct
21 Correct 183 ms 204 KB Output is correct
22 Correct 236 ms 308 KB Output is correct
23 Correct 198 ms 324 KB Output is correct
24 Correct 146 ms 324 KB Output is correct
25 Correct 276 ms 308 KB Output is correct
26 Correct 268 ms 324 KB Output is correct
27 Correct 215 ms 308 KB Output is correct
28 Correct 237 ms 308 KB Output is correct
29 Correct 201 ms 308 KB Output is correct
30 Correct 251 ms 204 KB Output is correct
31 Correct 210 ms 316 KB Output is correct
32 Correct 223 ms 332 KB Output is correct
33 Correct 196 ms 308 KB Output is correct
34 Correct 216 ms 204 KB Output is correct
35 Correct 229 ms 308 KB Output is correct
36 Correct 228 ms 332 KB Output is correct
37 Correct 238 ms 328 KB Output is correct
38 Correct 207 ms 308 KB Output is correct
39 Correct 233 ms 312 KB Output is correct
40 Correct 220 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 103 ms 312 KB Output is correct
17 Correct 133 ms 332 KB Output is correct
18 Correct 141 ms 204 KB Output is correct
19 Correct 223 ms 308 KB Output is correct
20 Correct 215 ms 324 KB Output is correct
21 Correct 183 ms 204 KB Output is correct
22 Correct 236 ms 308 KB Output is correct
23 Correct 198 ms 324 KB Output is correct
24 Correct 146 ms 324 KB Output is correct
25 Correct 276 ms 308 KB Output is correct
26 Correct 268 ms 324 KB Output is correct
27 Correct 215 ms 308 KB Output is correct
28 Correct 237 ms 308 KB Output is correct
29 Correct 201 ms 308 KB Output is correct
30 Correct 251 ms 204 KB Output is correct
31 Correct 210 ms 316 KB Output is correct
32 Correct 223 ms 332 KB Output is correct
33 Correct 196 ms 308 KB Output is correct
34 Correct 216 ms 204 KB Output is correct
35 Correct 229 ms 308 KB Output is correct
36 Correct 228 ms 332 KB Output is correct
37 Correct 238 ms 328 KB Output is correct
38 Correct 207 ms 308 KB Output is correct
39 Correct 233 ms 312 KB Output is correct
40 Correct 220 ms 204 KB Output is correct
41 Execution timed out 2569 ms 324 KB Time limit exceeded
42 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2587 ms 332 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Execution timed out 2597 ms 332 KB Time limit exceeded
6 Halted 0 ms 0 KB -