Submission #682002

# Submission time Handle Problem Language Result Execution time Memory
682002 2023-01-15T07:56:18 Z dsyz Let's Win the Election (JOI22_ho_t3) C++17
100 / 100
1681 ms 4428 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define MAXN (300005)
int main() {
	ios_base::sync_with_stdio(false);cin.tie(0);
	ll N,K;
	cin>>N>>K;
	deque<pair<ll,ll> > arr;
	for(ll i = 1;i <= N;i++){
		ll a,b;
		cin>>a>>b;
		if(b == -1) b = 1e18;
		arr.push_back(make_pair(b,a));
	}
	sort(arr.begin(),arr.end());
	arr.push_front(make_pair(0,0));
	ld A[N + 1], B[N + 1]; //1-indexed
	A[0] = 0;
	B[0] = 0;
	for(ll i = 1;i <= N;i++){
		A[i] = arr[i].second;
		B[i] = arr[i].first;
	}
	ld dp[N + 5][N + 5]; //first i states considered, j of them belong in B[i] = -1
	ld ans = 1e18;
	for(ll m = 0;m <= K;m++){ //m collaborators gained in total
		for(ll i = 0;i <= N;i++){
			for(ll j = 0;j <= N;j++){
				dp[i][j] = 1e18;
			}
		}
		dp[0][0] = 0;
		for(ll i = 1;i <= N;i++){ //first i states considered
			for(ll j = 0;j <= i;j++){ //j states are non-collaborators
				ld valA = A[i] / (m + 1);
				ld valB = B[i] / min(i - j,m);
				dp[i][j] = min(dp[i][j],dp[i - 1][j] + valB);
				if(i - j > m) dp[i][j] = min(dp[i][j],dp[i - 1][j]);
				if(j >= 1) dp[i][j] = min(dp[i][j],dp[i - 1][j - 1] + valA);
			}
		}
		ans = min(ans,dp[N][K - m]);
	}
	cout<<fixed<<setprecision(10);
	cout<<ans<<'\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 0 ms 324 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 178 ms 4316 KB Output is correct
6 Correct 431 ms 4428 KB Output is correct
7 Correct 828 ms 4312 KB Output is correct
8 Correct 1231 ms 4312 KB Output is correct
9 Correct 1586 ms 4320 KB Output is correct
10 Correct 1263 ms 4328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 0 ms 324 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 178 ms 4316 KB Output is correct
6 Correct 431 ms 4428 KB Output is correct
7 Correct 828 ms 4312 KB Output is correct
8 Correct 1231 ms 4312 KB Output is correct
9 Correct 1586 ms 4320 KB Output is correct
10 Correct 1263 ms 4328 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 536 ms 4316 KB Output is correct
13 Correct 518 ms 4316 KB Output is correct
14 Correct 535 ms 4316 KB Output is correct
15 Correct 1126 ms 4320 KB Output is correct
16 Correct 1183 ms 4316 KB Output is correct
17 Correct 1135 ms 4316 KB Output is correct
18 Correct 1633 ms 4312 KB Output is correct
19 Correct 1681 ms 4316 KB Output is correct
20 Correct 1574 ms 4316 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 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 0 ms 320 KB Output is correct
15 Correct 1 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 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 0 ms 320 KB Output is correct
15 Correct 1 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 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 320 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 0 ms 212 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 1 ms 212 KB Output is correct
35 Correct 1 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 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 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 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 0 ms 320 KB Output is correct
15 Correct 1 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 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 320 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 0 ms 212 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 1 ms 212 KB Output is correct
35 Correct 1 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 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 3 ms 468 KB Output is correct
42 Correct 3 ms 468 KB Output is correct
43 Correct 6 ms 496 KB Output is correct
44 Correct 5 ms 468 KB Output is correct
45 Correct 9 ms 492 KB Output is correct
46 Correct 8 ms 468 KB Output is correct
47 Correct 10 ms 496 KB Output is correct
48 Correct 9 ms 496 KB Output is correct
49 Correct 11 ms 468 KB Output is correct
50 Correct 11 ms 444 KB Output is correct
51 Correct 14 ms 468 KB Output is correct
52 Correct 14 ms 496 KB Output is correct
53 Correct 9 ms 492 KB Output is correct
54 Correct 10 ms 492 KB Output is correct
55 Correct 10 ms 468 KB Output is correct
56 Correct 11 ms 568 KB Output is correct
57 Correct 9 ms 504 KB Output is correct
58 Correct 9 ms 468 KB Output is correct
59 Correct 9 ms 496 KB Output is correct
60 Correct 10 ms 496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1558 ms 4316 KB Output is correct
2 Correct 1607 ms 4312 KB Output is correct
3 Correct 1586 ms 4316 KB Output is correct
4 Correct 1634 ms 4316 KB Output is correct
5 Correct 1599 ms 4328 KB Output is correct
6 Correct 1577 ms 4316 KB Output is correct
7 Correct 1574 ms 4332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 0 ms 324 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 178 ms 4316 KB Output is correct
6 Correct 431 ms 4428 KB Output is correct
7 Correct 828 ms 4312 KB Output is correct
8 Correct 1231 ms 4312 KB Output is correct
9 Correct 1586 ms 4320 KB Output is correct
10 Correct 1263 ms 4328 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 536 ms 4316 KB Output is correct
13 Correct 518 ms 4316 KB Output is correct
14 Correct 535 ms 4316 KB Output is correct
15 Correct 1126 ms 4320 KB Output is correct
16 Correct 1183 ms 4316 KB Output is correct
17 Correct 1135 ms 4316 KB Output is correct
18 Correct 1633 ms 4312 KB Output is correct
19 Correct 1681 ms 4316 KB Output is correct
20 Correct 1574 ms 4316 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 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 324 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 320 KB Output is correct
34 Correct 0 ms 320 KB Output is correct
35 Correct 1 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 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 320 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 0 ms 212 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 1 ms 212 KB Output is correct
53 Correct 1 ms 212 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 1 ms 212 KB Output is correct
56 Correct 1 ms 212 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 1 ms 212 KB Output is correct
61 Correct 3 ms 468 KB Output is correct
62 Correct 3 ms 468 KB Output is correct
63 Correct 6 ms 496 KB Output is correct
64 Correct 5 ms 468 KB Output is correct
65 Correct 9 ms 492 KB Output is correct
66 Correct 8 ms 468 KB Output is correct
67 Correct 10 ms 496 KB Output is correct
68 Correct 9 ms 496 KB Output is correct
69 Correct 11 ms 468 KB Output is correct
70 Correct 11 ms 444 KB Output is correct
71 Correct 14 ms 468 KB Output is correct
72 Correct 14 ms 496 KB Output is correct
73 Correct 9 ms 492 KB Output is correct
74 Correct 10 ms 492 KB Output is correct
75 Correct 10 ms 468 KB Output is correct
76 Correct 11 ms 568 KB Output is correct
77 Correct 9 ms 504 KB Output is correct
78 Correct 9 ms 468 KB Output is correct
79 Correct 9 ms 496 KB Output is correct
80 Correct 10 ms 496 KB Output is correct
81 Correct 1558 ms 4316 KB Output is correct
82 Correct 1607 ms 4312 KB Output is correct
83 Correct 1586 ms 4316 KB Output is correct
84 Correct 1634 ms 4316 KB Output is correct
85 Correct 1599 ms 4328 KB Output is correct
86 Correct 1577 ms 4316 KB Output is correct
87 Correct 1574 ms 4332 KB Output is correct
88 Correct 171 ms 4312 KB Output is correct
89 Correct 178 ms 4316 KB Output is correct
90 Correct 434 ms 4308 KB Output is correct
91 Correct 427 ms 4428 KB Output is correct
92 Correct 804 ms 4320 KB Output is correct
93 Correct 806 ms 4316 KB Output is correct
94 Correct 1186 ms 4316 KB Output is correct
95 Correct 1202 ms 4316 KB Output is correct
96 Correct 1397 ms 4320 KB Output is correct
97 Correct 1410 ms 4308 KB Output is correct
98 Correct 1114 ms 4320 KB Output is correct
99 Correct 1135 ms 4428 KB Output is correct
100 Correct 1109 ms 4316 KB Output is correct
101 Correct 1108 ms 4428 KB Output is correct
102 Correct 1124 ms 4308 KB Output is correct
103 Correct 1124 ms 4428 KB Output is correct
104 Correct 1109 ms 4428 KB Output is correct
105 Correct 1117 ms 4316 KB Output is correct