Submission #696082

# Submission time Handle Problem Language Result Execution time Memory
696082 2023-02-05T11:20:04 Z attemptn63 Let's Win the Election (JOI22_ho_t3) C++17
100 / 100
1249 ms 4644 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define double long double
#define endl '\n'
#define all(k) (k).begin(), (k).end()
#define pb push_back
#define fi first
#define se second
#define sz(k) (int)(k).size()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pi pair<long long, long long>
#define mp make_pair
#define ti tuple<long long, long long, long long>
#define INF (long long)1e18
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)
#define sign(x) ((x > 0) - (x < 0))
template <class T>using vec = vector<T>;
template <class T>using min_heap = priority_queue<T, vec<T>, greater<T>>;
template <class T>using max_heap = priority_queue<T>;
template <class T>using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T>using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
#ifdef DEBUG
template <typename T>
inline void debug(T k){
	cout << k << " ";
}
template <typename T, typename... Args>
inline void debug(T k, Args... args){
	cout << k << " | ";
	debug(args...);
}
#define debug(...) cout << "[" << #__VA_ARGS__ << "] : ";debug(__VA_ARGS__);cout << endl
template <typename T>
ostream &operator<<(ostream &o_str, const vec<T> &p){
	o_str << "{ ";
	for (auto i = 0; i < (int)p.size(); i++){
		o_str << p[i];
		if (i < (int)p.size() - 1){
			o_str << ", ";
		}
	}
	return o_str << " }" << endl;
}
template <typename T>
ostream &operator<<(ostream &o_str, const deque<T> &p){
	o_str << "{ ";
	for (auto i = 0; i < (int)p.size(); i++){
		o_str << p[i];
		if (i < (int)p.size() - 1){
			o_str << ", ";
		}
	}
	return o_str << " }" << endl;
}
template <typename T, typename U>
ostream &operator<<(ostream &o_str, const pair<T, U> &p){
	return o_str << "(" << p.fi << ", " << p.se << ")";
}
template <typename T, typename U, typename V>
ostream &operator<<(ostream &o_str, const tuple<T, U, V> &p){
	return o_str << "(" << get<0>(p) << ", " << get<1>(p) << ", " << get<2>(p) << ")";
}
template <typename T>
ostream &operator<<(ostream &o_str, const set<T> &p){
	o_str << "{ ";
	for (auto i = p.begin(); i != p.end(); i++){
		o_str << *i;
		if (i != --p.end()){
			o_str << ", ";
		}
	}
	return o_str << " }" << endl;
}
template <typename T, typename U>
ostream &operator<<(ostream &o_str, const map<T, U> &p){
	o_str << "{ ";
	for (auto i = p.begin(); i != p.end(); i++){
		o_str << i->first << ": " << i->second;
		if (i != --p.end()){
			o_str << ", ";
		}
	}
	return o_str << " }" << endl;
}
template <typename T>
ostream &operator<<(ostream &o_str, const queue<T> &p){
	queue<T> q = p;
	o_str << "{ ";
	while (!q.empty()){
		o_str << q.front();
		q.pop();
		if (!q.empty()){
			o_str << ", ";
		}
	}
	return o_str << " }" << endl;
}
template <typename T, typename U, typename cmp>
ostream &operator<<(ostream &o_str, const priority_queue<T,U,cmp> &p){
	priority_queue<T,U,cmp> q = p;
	o_str << "{ ";
	while (!q.empty()){
		o_str << q.top();
		q.pop();
		if (!q.empty()){
			o_str << ", ";
		}
	}
	return o_str << " }" << endl;
}
template <typename T, typename U>
ostream &operator<<(ostream &o_str, const set<T, U> &p){
	o_str << "{ ";
	for (auto i = p.begin(); i != p.end(); i++){
		o_str << *i;
		if (i != --p.end()){
			o_str << ", ";
		}
	}
	return o_str << " }" << endl;
}
template<typename T, typename U>
ostream &operator<<(ostream &o_str, const multiset<T, U> &p){
	o_str << "{ ";
	for (auto i = p.begin(); i != p.end(); i++){
		o_str << *i;
		if (i != --p.end()){
			o_str << ", ";
		}
	}
	return o_str << " }" << endl;
}
#else
template <typename T>
inline void debug(T k){}
template <typename T, typename... Args>
inline void debug(T k, Args... args) {}
#define debug(...)
template <typename T>
ostream &operator<<(ostream &o_str, const vec<T> &p){return o_str;}
template <typename T>
ostream &operator<<(ostream &o_str, const deque<T> &p) { return o_str; }
template <typename T, typename U>
ostream &operator<<(ostream &o_str, const pair<T, U> &p) { return o_str; }
template <typename T, typename U, typename V>
ostream &operator<<(ostream &o_str, const tuple<T, U, V> &p) { return o_str; }
template <typename T>
ostream &operator<<(ostream &o_str, const set<T> &p) { return o_str; }
template <typename T, typename U>
ostream &operator<<(ostream &o_str, const map<T, U> &p) { return o_str; }
template <typename T>
ostream &operator<<(ostream &o_str, const queue<T> &p) { return o_str; }
template <typename T, typename U, typename cmp>
ostream &operator<<(ostream &o_str, const priority_queue<T,U,cmp> &p){return o_str;}
template <typename T, typename U>
ostream &operator<<(ostream &o_str, const set<T, U> &p) { return o_str; }
template<typename T, typename U>
ostream &operator<<(ostream &o_str, const multiset<T, U> &p) { return o_str; }
#endif

int n,k;
vec<pi> a;
double solve(int collab){
	vec<vec<double>> dp(n + 1, vec<double>(n + 1, 1e18));
	dp[0][0] = 0;
	for(int i = 1;i <= n; i++){
		for(int anum = 0; anum <= min(i - 1, k - collab);anum++){
			int bnum = min(collab, i - 1 - anum);
			if(anum < k - collab){
				dp[i][anum + 1] = min(dp[i][anum + 1], dp[i-1][anum] + (double)a[i].fi/(collab+1));
			}
			if(bnum < collab){
				dp[i][anum] = min(dp[i][anum], dp[i-1][anum] + (double)a[i].se/(bnum+1));
			}
			else dp[i][anum] = min(dp[i][anum], dp[i-1][anum]);
		}
	}
	return dp[n][k - collab];
}
signed main(){
	speed;
	cin >> n >> k;
	a.resize(n+1, {0,0});
	for(int i = 1; i <= n; i++){
		cin >> a[i].fi >> a[i].se;
		if(a[i].se == -1){
			a[i].se = INF;
		}
	}
	sort(all(a), [&](pi x, pi y){
		return (x.se == y.se ? x.fi < y.fi : x.se < y.se);
	});
	cout<<a;
	double ans = INF;
	for(int i = 0; i <= k; i++){
		ans = min(ans, solve(i));
	}
	cout << fixed << setprecision(10) << ans << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 98 ms 4384 KB Output is correct
6 Correct 220 ms 4496 KB Output is correct
7 Correct 513 ms 4600 KB Output is correct
8 Correct 928 ms 4400 KB Output is correct
9 Correct 1185 ms 4488 KB Output is correct
10 Correct 883 ms 4408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 98 ms 4384 KB Output is correct
6 Correct 220 ms 4496 KB Output is correct
7 Correct 513 ms 4600 KB Output is correct
8 Correct 928 ms 4400 KB Output is correct
9 Correct 1185 ms 4488 KB Output is correct
10 Correct 883 ms 4408 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 305 ms 4392 KB Output is correct
13 Correct 306 ms 4480 KB Output is correct
14 Correct 258 ms 4464 KB Output is correct
15 Correct 728 ms 4588 KB Output is correct
16 Correct 673 ms 4496 KB Output is correct
17 Correct 738 ms 4604 KB Output is correct
18 Correct 1088 ms 4536 KB Output is correct
19 Correct 1087 ms 4592 KB Output is correct
20 Correct 1217 ms 4480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 320 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 320 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 320 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 320 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 1 ms 492 KB Output is correct
42 Correct 1 ms 480 KB Output is correct
43 Correct 2 ms 484 KB Output is correct
44 Correct 2 ms 484 KB Output is correct
45 Correct 4 ms 484 KB Output is correct
46 Correct 4 ms 484 KB Output is correct
47 Correct 4 ms 480 KB Output is correct
48 Correct 6 ms 476 KB Output is correct
49 Correct 7 ms 484 KB Output is correct
50 Correct 5 ms 484 KB Output is correct
51 Correct 7 ms 476 KB Output is correct
52 Correct 7 ms 484 KB Output is correct
53 Correct 4 ms 484 KB Output is correct
54 Correct 5 ms 484 KB Output is correct
55 Correct 4 ms 488 KB Output is correct
56 Correct 4 ms 484 KB Output is correct
57 Correct 5 ms 484 KB Output is correct
58 Correct 4 ms 480 KB Output is correct
59 Correct 4 ms 484 KB Output is correct
60 Correct 4 ms 484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1170 ms 4512 KB Output is correct
2 Correct 1159 ms 4536 KB Output is correct
3 Correct 1126 ms 4552 KB Output is correct
4 Correct 1196 ms 4456 KB Output is correct
5 Correct 1135 ms 4548 KB Output is correct
6 Correct 1249 ms 4588 KB Output is correct
7 Correct 1139 ms 4552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 98 ms 4384 KB Output is correct
6 Correct 220 ms 4496 KB Output is correct
7 Correct 513 ms 4600 KB Output is correct
8 Correct 928 ms 4400 KB Output is correct
9 Correct 1185 ms 4488 KB Output is correct
10 Correct 883 ms 4408 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 305 ms 4392 KB Output is correct
13 Correct 306 ms 4480 KB Output is correct
14 Correct 258 ms 4464 KB Output is correct
15 Correct 728 ms 4588 KB Output is correct
16 Correct 673 ms 4496 KB Output is correct
17 Correct 738 ms 4604 KB Output is correct
18 Correct 1088 ms 4536 KB Output is correct
19 Correct 1087 ms 4592 KB Output is correct
20 Correct 1217 ms 4480 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 320 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 1 ms 320 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
51 Correct 0 ms 212 KB Output is correct
52 Correct 1 ms 212 KB Output is correct
53 Correct 0 ms 212 KB Output is correct
54 Correct 0 ms 212 KB Output is correct
55 Correct 1 ms 212 KB Output is correct
56 Correct 1 ms 320 KB Output is correct
57 Correct 1 ms 212 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 0 ms 212 KB Output is correct
61 Correct 1 ms 492 KB Output is correct
62 Correct 1 ms 480 KB Output is correct
63 Correct 2 ms 484 KB Output is correct
64 Correct 2 ms 484 KB Output is correct
65 Correct 4 ms 484 KB Output is correct
66 Correct 4 ms 484 KB Output is correct
67 Correct 4 ms 480 KB Output is correct
68 Correct 6 ms 476 KB Output is correct
69 Correct 7 ms 484 KB Output is correct
70 Correct 5 ms 484 KB Output is correct
71 Correct 7 ms 476 KB Output is correct
72 Correct 7 ms 484 KB Output is correct
73 Correct 4 ms 484 KB Output is correct
74 Correct 5 ms 484 KB Output is correct
75 Correct 4 ms 488 KB Output is correct
76 Correct 4 ms 484 KB Output is correct
77 Correct 5 ms 484 KB Output is correct
78 Correct 4 ms 480 KB Output is correct
79 Correct 4 ms 484 KB Output is correct
80 Correct 4 ms 484 KB Output is correct
81 Correct 1170 ms 4512 KB Output is correct
82 Correct 1159 ms 4536 KB Output is correct
83 Correct 1126 ms 4552 KB Output is correct
84 Correct 1196 ms 4456 KB Output is correct
85 Correct 1135 ms 4548 KB Output is correct
86 Correct 1249 ms 4588 KB Output is correct
87 Correct 1139 ms 4552 KB Output is correct
88 Correct 75 ms 4532 KB Output is correct
89 Correct 81 ms 4392 KB Output is correct
90 Correct 214 ms 4516 KB Output is correct
91 Correct 223 ms 4444 KB Output is correct
92 Correct 502 ms 4644 KB Output is correct
93 Correct 487 ms 4404 KB Output is correct
94 Correct 829 ms 4428 KB Output is correct
95 Correct 826 ms 4628 KB Output is correct
96 Correct 980 ms 4568 KB Output is correct
97 Correct 977 ms 4468 KB Output is correct
98 Correct 762 ms 4556 KB Output is correct
99 Correct 763 ms 4452 KB Output is correct
100 Correct 724 ms 4596 KB Output is correct
101 Correct 735 ms 4532 KB Output is correct
102 Correct 692 ms 4416 KB Output is correct
103 Correct 713 ms 4436 KB Output is correct
104 Correct 744 ms 4372 KB Output is correct
105 Correct 691 ms 4384 KB Output is correct