Submission #533059

# Submission time Handle Problem Language Result Execution time Memory
533059 2022-03-04T14:57:10 Z victor_gao Let's Win the Election (JOI22_ho_t3) C++17
11 / 100
2500 ms 424 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][N],ans=1e100;
bool vis[N];
vector<int>np;
void solve(){
	do {
		for (int i=1;i<=n;i++){
			for (int j=0;j<=n;j++) dp[i][j]=1e100;
		}
		for (int i=1;i<=np.size();i++){
			for (int j=0;j<=i;j++){
				if (j!=i) dp[i][j]=min(dp[i][j],dp[i-1][j]+(long double)a[np[i-1]]/(long double)(j+1));
				if (j&&b[np[i-1]]!=-1) dp[i][j]=min(dp[i][j],dp[i-1][j-1]+(long double)b[np[i-1]]/(long double)(j));
			}
		}
		long double tans=1e100;
		for (int i=0;i<np.size();i++){
			tans=min(tans,dp[np.size()][i]);
		}
		ans=min(tans,ans);
	//	for (auto i:np) cout<<i;
	//	cout<<" -> "<<tans<<'\n';
	}while (next_permutation(np.begin(),np.end()));
}
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++){
		np.clear();
		for (int j=0;j<n;j++){
			if (i&(1LL<<j)){
				np.push_back(j);
			}
		}
		if (np.size()==k) solve();
	}
	cout<<ans<<'\n';
}

Compilation message

Main.cpp: In function 'void solve()':
Main.cpp:26:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |   for (int i=1;i<=np.size();i++){
      |                ~^~~~~~~~~~~
Main.cpp:33:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |   for (int i=0;i<np.size();i++){
      |                ~^~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:55:16: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   55 |   if (np.size()==k) solve();
      |       ~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 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 312 KB Output is correct
5 Execution timed out 2568 ms 332 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 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 312 KB Output is correct
5 Execution timed out 2568 ms 332 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 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 2 ms 332 KB Output is correct
5 Correct 3 ms 332 KB Output is correct
6 Correct 4 ms 332 KB Output is correct
7 Correct 6 ms 332 KB Output is correct
8 Correct 2 ms 332 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 3 ms 332 KB Output is correct
12 Correct 2 ms 332 KB Output is correct
13 Correct 2 ms 328 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 5 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 2 ms 332 KB Output is correct
5 Correct 3 ms 332 KB Output is correct
6 Correct 4 ms 332 KB Output is correct
7 Correct 6 ms 332 KB Output is correct
8 Correct 2 ms 332 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 3 ms 332 KB Output is correct
12 Correct 2 ms 332 KB Output is correct
13 Correct 2 ms 328 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 5 ms 332 KB Output is correct
16 Correct 117 ms 424 KB Output is correct
17 Execution timed out 2581 ms 332 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 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 2 ms 332 KB Output is correct
5 Correct 3 ms 332 KB Output is correct
6 Correct 4 ms 332 KB Output is correct
7 Correct 6 ms 332 KB Output is correct
8 Correct 2 ms 332 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 3 ms 332 KB Output is correct
12 Correct 2 ms 332 KB Output is correct
13 Correct 2 ms 328 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 5 ms 332 KB Output is correct
16 Correct 117 ms 424 KB Output is correct
17 Execution timed out 2581 ms 332 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2557 ms 332 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 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 312 KB Output is correct
5 Execution timed out 2568 ms 332 KB Time limit exceeded
6 Halted 0 ms 0 KB -