Submission #576897

# Submission time Handle Problem Language Result Execution time Memory
576897 2022-06-13T17:53:44 Z cheissmart Let's Win the Election (JOI22_ho_t3) C++14
100 / 100
513 ms 1136 KB
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

string _reset = "\u001b[0m", _yellow = "\u001b[33m", _bold = "\u001b[1m";
void DBG() { cerr << "]" << _reset << endl; }
template<class H, class...T> void DBG(H h, T ...t) {
	cerr << to_string(h);
	if(sizeof ...(t)) cerr << ", ";
	DBG(t...);
}
#ifdef CHEISSMART
#define debug(...) cerr << _yellow << _bold << "Line(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define debug(...)
#endif

const int INF = 1e9 + 7;

vi pre[505];

signed main()
{
	IO_OP;

	int n, k;
	cin >> n >> k;
	V<pi> a(n);
	for(int i = 0; i < n; i++) {
		cin >> a[i].S >> a[i].F;
		if(a[i].F == -1) a[i].F = INF;
	}
	sort(ALL(a));

	for(int he = 0; he < n; he++) {
		vi aux;
		for(int i = he; i < n; i++)
			aux.PB(a[i].S);
		sort(ALL(aux));
		pre[he] = aux;
	}

	auto solve = [&] (int be) {
		// b: 1, 1/2, 1/3..., 1/be 
		// a: 1/(be + 1)
		V<double> dp(be + 1, INF);
		dp[0] = 0;

		auto go = [&] (int he) {
			double ans = dp[be];
			vi aux = pre[he];
			for(int i = 0; i < k - he; i++)
				ans += 1. * aux[i] / (be + 1);
			return ans;
		};

		double ans = INF;
		ans = min(ans, go(0));
		for(int i = 0; i < k; i++) {
			V<double> ndp(be + 1, INF);
			for(int j = 0; j <= be; j++) if(dp[j] != INF) {
				// a
				ndp[j] = min(ndp[j], dp[j] + 1. * a[i].S / (be + 1));

				// b
				if(j + 1 <= be)
					ndp[j + 1] = min(ndp[j + 1], dp[j] + 1. * a[i].F / (j + 1));
			}
			swap(dp, ndp);
			ans = min(ans, go(i + 1));
		}

		return ans;
	};

	double ans = INF;
	for(int be = 0; be <= k; be++)
		ans = min(ans, solve(be));
	cout << fixed << setprecision(10) << ans << '\n';
}

# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 3 ms 724 KB Output is correct
6 Correct 9 ms 880 KB Output is correct
7 Correct 53 ms 848 KB Output is correct
8 Correct 175 ms 912 KB Output is correct
9 Correct 376 ms 980 KB Output is correct
10 Correct 134 ms 852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 3 ms 724 KB Output is correct
6 Correct 9 ms 880 KB Output is correct
7 Correct 53 ms 848 KB Output is correct
8 Correct 175 ms 912 KB Output is correct
9 Correct 376 ms 980 KB Output is correct
10 Correct 134 ms 852 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 20 ms 888 KB Output is correct
13 Correct 20 ms 892 KB Output is correct
14 Correct 19 ms 860 KB Output is correct
15 Correct 174 ms 908 KB Output is correct
16 Correct 183 ms 900 KB Output is correct
17 Correct 180 ms 852 KB Output is correct
18 Correct 496 ms 1048 KB Output is correct
19 Correct 510 ms 916 KB Output is correct
20 Correct 477 ms 972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 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 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 1 ms 340 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 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 1 ms 340 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 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 2 ms 340 KB Output is correct
48 Correct 2 ms 340 KB Output is correct
49 Correct 3 ms 340 KB Output is correct
50 Correct 3 ms 368 KB Output is correct
51 Correct 5 ms 368 KB Output is correct
52 Correct 5 ms 340 KB Output is correct
53 Correct 2 ms 340 KB Output is correct
54 Correct 2 ms 340 KB Output is correct
55 Correct 2 ms 352 KB Output is correct
56 Correct 2 ms 340 KB Output is correct
57 Correct 2 ms 340 KB Output is correct
58 Correct 3 ms 340 KB Output is correct
59 Correct 3 ms 340 KB Output is correct
60 Correct 3 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 499 ms 1004 KB Output is correct
2 Correct 509 ms 872 KB Output is correct
3 Correct 487 ms 920 KB Output is correct
4 Correct 513 ms 1052 KB Output is correct
5 Correct 477 ms 928 KB Output is correct
6 Correct 491 ms 924 KB Output is correct
7 Correct 492 ms 932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 3 ms 724 KB Output is correct
6 Correct 9 ms 880 KB Output is correct
7 Correct 53 ms 848 KB Output is correct
8 Correct 175 ms 912 KB Output is correct
9 Correct 376 ms 980 KB Output is correct
10 Correct 134 ms 852 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 20 ms 888 KB Output is correct
13 Correct 20 ms 892 KB Output is correct
14 Correct 19 ms 860 KB Output is correct
15 Correct 174 ms 908 KB Output is correct
16 Correct 183 ms 900 KB Output is correct
17 Correct 180 ms 852 KB Output is correct
18 Correct 496 ms 1048 KB Output is correct
19 Correct 510 ms 916 KB Output is correct
20 Correct 477 ms 972 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 0 ms 212 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
51 Correct 0 ms 212 KB Output is correct
52 Correct 0 ms 212 KB Output is correct
53 Correct 1 ms 212 KB Output is correct
54 Correct 0 ms 212 KB Output is correct
55 Correct 0 ms 212 KB Output is correct
56 Correct 0 ms 212 KB Output is correct
57 Correct 1 ms 340 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 340 KB Output is correct
62 Correct 1 ms 340 KB Output is correct
63 Correct 1 ms 340 KB Output is correct
64 Correct 1 ms 340 KB Output is correct
65 Correct 1 ms 340 KB Output is correct
66 Correct 1 ms 340 KB Output is correct
67 Correct 2 ms 340 KB Output is correct
68 Correct 2 ms 340 KB Output is correct
69 Correct 3 ms 340 KB Output is correct
70 Correct 3 ms 368 KB Output is correct
71 Correct 5 ms 368 KB Output is correct
72 Correct 5 ms 340 KB Output is correct
73 Correct 2 ms 340 KB Output is correct
74 Correct 2 ms 340 KB Output is correct
75 Correct 2 ms 352 KB Output is correct
76 Correct 2 ms 340 KB Output is correct
77 Correct 2 ms 340 KB Output is correct
78 Correct 3 ms 340 KB Output is correct
79 Correct 3 ms 340 KB Output is correct
80 Correct 3 ms 340 KB Output is correct
81 Correct 499 ms 1004 KB Output is correct
82 Correct 509 ms 872 KB Output is correct
83 Correct 487 ms 920 KB Output is correct
84 Correct 513 ms 1052 KB Output is correct
85 Correct 477 ms 928 KB Output is correct
86 Correct 491 ms 924 KB Output is correct
87 Correct 492 ms 932 KB Output is correct
88 Correct 7 ms 852 KB Output is correct
89 Correct 8 ms 844 KB Output is correct
90 Correct 14 ms 904 KB Output is correct
91 Correct 16 ms 848 KB Output is correct
92 Correct 71 ms 844 KB Output is correct
93 Correct 70 ms 856 KB Output is correct
94 Correct 225 ms 1136 KB Output is correct
95 Correct 220 ms 920 KB Output is correct
96 Correct 356 ms 928 KB Output is correct
97 Correct 370 ms 1048 KB Output is correct
98 Correct 174 ms 912 KB Output is correct
99 Correct 183 ms 908 KB Output is correct
100 Correct 202 ms 972 KB Output is correct
101 Correct 189 ms 860 KB Output is correct
102 Correct 170 ms 908 KB Output is correct
103 Correct 185 ms 920 KB Output is correct
104 Correct 190 ms 880 KB Output is correct
105 Correct 170 ms 920 KB Output is correct