Submission #843974

# Submission time Handle Problem Language Result Execution time Memory
843974 2023-09-04T18:46:57 Z jmyszka2007 Let's Win the Election (JOI22_ho_t3) C++17
100 / 100
388 ms 604 KB
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
template<class A, class B>
ostream& operator<<(ostream& o, const pair<A, B>& p) {return o << '(' << p.first << ", " << p.second << ')';}
template<size_t Index = 0, typename... Types>
ostream& printTupleElements(ostream& o, const tuple<Types...>& t) {if constexpr (Index < sizeof...(Types)){if(Index > 0){o << ", ";}o << get<Index>(t);printTupleElements<Index + 1>(o, t);}return o;}
template<typename... Types>
ostream& operator<<(ostream& o, const tuple<Types...>& t){o << "(";printTupleElements(o, t);return o << ")";}
template<class T>
auto operator<<(ostream& o, const T& x) -> decltype(x.end(), o){o << '{';bool first = true;for (const auto& e : x){if (!first){o << ", ";}o << e;first = false;} return o << '}';}
#define DEBUG
#ifdef DEBUG
#define fastio()
#define debug(x...) cerr << "[" #x "]: ", [](auto... $) {((cerr << $ << "; "), ...); }(x), cerr << '\n'
#define check(x) if (!(x)) { cerr << "Check failed: " << #x << " in line " << __LINE__ << endl; exit(1); }
#else
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0);
#define debug(...)
#define check(x) 
#endif
typedef long long ll;
typedef long double ld;
#define pi pair<int, int>
#define pl pair<ll, ll>
#define st first
#define nd second
#define vi vector<int>
#define vll vector<ll>
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
vector<pair<ld, ld> >prz;
int n, k;
ld cntdp(int x) {
	vector<ld>dp(k - x + 1, 1e9);
	dp[0] = 0;
	for(int i = 0; i < sz(prz); i++) {
		for(int j = min(i + 1, k - x); j >= 0; j--) {
			ld popdp = dp[j];
			if(j > 0) {
				dp[j] = dp[j - 1] + prz[i].nd / (ld)(x + 1);
			}
			else {
				dp[j] = 1e9;
			}
			if(0 < (i + 1) - j && (i + 1) - j <= x) {
				dp[j] = min(dp[j], popdp + prz[i].st / (ld)((i + 1) - j));
			}
			else {
				dp[j] = min(dp[j], popdp);
			}
		}
	}
	return dp[k - x];
}
void solve() {
	//ifstream cin("nazwa.in");
	//ofstream cout("nazwa.out");
	cin >> n >> k;
	for(int i = 1; i <= n; i++) {
		int a, b;
		cin >> a >> b;
		if(b == -1) {
			b = 1e9;
		}
		prz.eb(b, a);
	}
	sort(all(prz));
	ld ans = 1e9;
	for(int i = 0; i <= k; i++) {
		ans = min(ans, cntdp(i));
	}
	cout.precision(9);
	cout << fixed << ans << '\n';
}
int main() {
	fastio();
	int t;
	//cin >> t;
	t = 1;	
	while(t--) {
		solve();
	}
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 6 ms 464 KB Output is correct
6 Correct 30 ms 464 KB Output is correct
7 Correct 108 ms 444 KB Output is correct
8 Correct 227 ms 440 KB Output is correct
9 Correct 369 ms 600 KB Output is correct
10 Correct 197 ms 444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 6 ms 464 KB Output is correct
6 Correct 30 ms 464 KB Output is correct
7 Correct 108 ms 444 KB Output is correct
8 Correct 227 ms 440 KB Output is correct
9 Correct 369 ms 600 KB Output is correct
10 Correct 197 ms 444 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 42 ms 460 KB Output is correct
13 Correct 42 ms 344 KB Output is correct
14 Correct 45 ms 344 KB Output is correct
15 Correct 196 ms 344 KB Output is correct
16 Correct 197 ms 444 KB Output is correct
17 Correct 203 ms 344 KB Output is correct
18 Correct 363 ms 444 KB Output is correct
19 Correct 368 ms 440 KB Output is correct
20 Correct 360 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 440 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 432 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 440 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 440 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 432 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 440 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 604 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 356 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 356 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 352 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 352 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 440 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 432 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 440 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 604 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 356 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 356 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 352 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 352 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 356 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 0 ms 356 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 2 ms 348 KB Output is correct
48 Correct 2 ms 348 KB Output is correct
49 Correct 2 ms 348 KB Output is correct
50 Correct 2 ms 348 KB Output is correct
51 Correct 3 ms 348 KB Output is correct
52 Correct 3 ms 348 KB Output is correct
53 Correct 2 ms 348 KB Output is correct
54 Correct 2 ms 348 KB Output is correct
55 Correct 2 ms 348 KB Output is correct
56 Correct 2 ms 348 KB Output is correct
57 Correct 2 ms 348 KB Output is correct
58 Correct 2 ms 348 KB Output is correct
59 Correct 2 ms 348 KB Output is correct
60 Correct 2 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 357 ms 348 KB Output is correct
2 Correct 388 ms 592 KB Output is correct
3 Correct 358 ms 348 KB Output is correct
4 Correct 357 ms 588 KB Output is correct
5 Correct 373 ms 456 KB Output is correct
6 Correct 378 ms 452 KB Output is correct
7 Correct 362 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 6 ms 464 KB Output is correct
6 Correct 30 ms 464 KB Output is correct
7 Correct 108 ms 444 KB Output is correct
8 Correct 227 ms 440 KB Output is correct
9 Correct 369 ms 600 KB Output is correct
10 Correct 197 ms 444 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 42 ms 460 KB Output is correct
13 Correct 42 ms 344 KB Output is correct
14 Correct 45 ms 344 KB Output is correct
15 Correct 196 ms 344 KB Output is correct
16 Correct 197 ms 444 KB Output is correct
17 Correct 203 ms 344 KB Output is correct
18 Correct 363 ms 444 KB Output is correct
19 Correct 368 ms 440 KB Output is correct
20 Correct 360 ms 348 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 440 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 1 ms 432 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 440 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 1 ms 344 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 604 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 356 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 ms 356 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 0 ms 352 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 0 ms 352 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 0 ms 356 KB Output is correct
61 Correct 1 ms 348 KB Output is correct
62 Correct 0 ms 356 KB Output is correct
63 Correct 1 ms 348 KB Output is correct
64 Correct 1 ms 348 KB Output is correct
65 Correct 1 ms 348 KB Output is correct
66 Correct 1 ms 348 KB Output is correct
67 Correct 2 ms 348 KB Output is correct
68 Correct 2 ms 348 KB Output is correct
69 Correct 2 ms 348 KB Output is correct
70 Correct 2 ms 348 KB Output is correct
71 Correct 3 ms 348 KB Output is correct
72 Correct 3 ms 348 KB Output is correct
73 Correct 2 ms 348 KB Output is correct
74 Correct 2 ms 348 KB Output is correct
75 Correct 2 ms 348 KB Output is correct
76 Correct 2 ms 348 KB Output is correct
77 Correct 2 ms 348 KB Output is correct
78 Correct 2 ms 348 KB Output is correct
79 Correct 2 ms 348 KB Output is correct
80 Correct 2 ms 348 KB Output is correct
81 Correct 357 ms 348 KB Output is correct
82 Correct 388 ms 592 KB Output is correct
83 Correct 358 ms 348 KB Output is correct
84 Correct 357 ms 588 KB Output is correct
85 Correct 373 ms 456 KB Output is correct
86 Correct 378 ms 452 KB Output is correct
87 Correct 362 ms 348 KB Output is correct
88 Correct 6 ms 348 KB Output is correct
89 Correct 6 ms 348 KB Output is correct
90 Correct 30 ms 348 KB Output is correct
91 Correct 31 ms 604 KB Output is correct
92 Correct 108 ms 440 KB Output is correct
93 Correct 110 ms 600 KB Output is correct
94 Correct 223 ms 348 KB Output is correct
95 Correct 237 ms 596 KB Output is correct
96 Correct 304 ms 348 KB Output is correct
97 Correct 311 ms 444 KB Output is correct
98 Correct 197 ms 444 KB Output is correct
99 Correct 196 ms 440 KB Output is correct
100 Correct 204 ms 444 KB Output is correct
101 Correct 197 ms 348 KB Output is correct
102 Correct 196 ms 348 KB Output is correct
103 Correct 195 ms 456 KB Output is correct
104 Correct 195 ms 448 KB Output is correct
105 Correct 200 ms 604 KB Output is correct