#ifdef LOCAL
//#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#include <random>
#ifndef LOCAL
//#pragma GCC optimize("O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,bmi,bmi2,popcnt,lzcnt")
#endif
using namespace std;
using ll = long long;
using ld = long double;
#define x first
#define y second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
mt19937_64 mt(418);
void solve();
void init();
int32_t main() {
#ifndef LOCAL
cin.tie(nullptr)->sync_with_stdio(false);
#endif
// srand(time(0));
init();
cout << fixed << setprecision(20);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
}
void init() {}
bool cmp(const pair<int, int>& a, const pair<int, int>& b) {
if (a.y < b.y) {
return true;
}
if (a.y > b.y) {
return false;
}
return a.x < b.x;
}
double dp[510][510][510]{};
void solve() {
int n, k;
cin >> n >> k;
vector<pair<int, int>> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i].x >> a[i].y;
if (a[i].y == -1) {
a[i].y = INT32_MAX / 2;
}
}
double ans = 2e18;
// vector<vector<vector<double>>> dp(n + 1, vector<vector<double>>(k + 1, vector<double>(n + 1, 2e18)));
for (int i = 0; i < 510; i++) {
for (int j = 0; j < 510; j++) {
for (int l = 0; l < 510; l++) {
dp[i][j][l] = 2e18;
}
}
}
for (int ll = 0; ll <= n; ll++) {
sort(all(a), cmp);
for (int i = 0; i < n; i++) {
for (int j = 0; j <= k; j++) {
if (i == j - 1) {
for (int l = 0; l <= n; l++) {
dp[i + 1][j][l] = 3e18;
}
} else {
dp[i + 1][j][ll] = 3e18;
}
}
}
dp[0][0][0] = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j <= k; j++) {
if (i == j - 1) {
for (int l = 0; l <= n; l++) {
dp[i + 1][j][l] = min(dp[i + 1][j][l], dp[i][j][l]);
if (j > 0) {
dp[i + 1][j][l] = min(dp[i + 1][j][l], dp[i][j - 1][l] + a[i].x / (double)(ll + 1));
if (l > 0) {
dp[i + 1][j][l] = min(dp[i + 1][j][l], dp[i][j - 1][l - 1] + a[i].y / (double)l);
}
}
}
} else {
dp[i + 1][j][ll] = min(dp[i + 1][j][ll], dp[i][j][ll]);
if (j > 0) {
dp[i + 1][j][ll] = min(dp[i + 1][j][ll], dp[i][j - 1][ll] + a[i].x / (double)(ll + 1));
}
}
}
}
for (int i = ll; i <= n; i++) {
ans = min(ans, dp[n][k][i]);
}
}
cout << ans << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
337 ms |
1038776 KB |
Output is correct |
2 |
Correct |
193 ms |
1038676 KB |
Output is correct |
3 |
Correct |
197 ms |
1038892 KB |
Output is correct |
4 |
Correct |
199 ms |
1038932 KB |
Output is correct |
5 |
Correct |
364 ms |
1038672 KB |
Output is correct |
6 |
Correct |
699 ms |
1038856 KB |
Output is correct |
7 |
Correct |
1240 ms |
1038804 KB |
Output is correct |
8 |
Correct |
2001 ms |
1038808 KB |
Output is correct |
9 |
Execution timed out |
2537 ms |
1038676 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
337 ms |
1038776 KB |
Output is correct |
2 |
Correct |
193 ms |
1038676 KB |
Output is correct |
3 |
Correct |
197 ms |
1038892 KB |
Output is correct |
4 |
Correct |
199 ms |
1038932 KB |
Output is correct |
5 |
Correct |
364 ms |
1038672 KB |
Output is correct |
6 |
Correct |
699 ms |
1038856 KB |
Output is correct |
7 |
Correct |
1240 ms |
1038804 KB |
Output is correct |
8 |
Correct |
2001 ms |
1038808 KB |
Output is correct |
9 |
Execution timed out |
2537 ms |
1038676 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
159 ms |
1038720 KB |
Output is correct |
2 |
Correct |
147 ms |
1038672 KB |
Output is correct |
3 |
Correct |
164 ms |
1038600 KB |
Output is correct |
4 |
Correct |
149 ms |
1038736 KB |
Output is correct |
5 |
Correct |
174 ms |
1038676 KB |
Output is correct |
6 |
Correct |
158 ms |
1038672 KB |
Output is correct |
7 |
Correct |
168 ms |
1038676 KB |
Output is correct |
8 |
Correct |
150 ms |
1038848 KB |
Output is correct |
9 |
Correct |
166 ms |
1038672 KB |
Output is correct |
10 |
Correct |
144 ms |
1038632 KB |
Output is correct |
11 |
Correct |
147 ms |
1038704 KB |
Output is correct |
12 |
Correct |
145 ms |
1038672 KB |
Output is correct |
13 |
Correct |
146 ms |
1038672 KB |
Output is correct |
14 |
Correct |
143 ms |
1038676 KB |
Output is correct |
15 |
Correct |
150 ms |
1038772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
159 ms |
1038720 KB |
Output is correct |
2 |
Correct |
147 ms |
1038672 KB |
Output is correct |
3 |
Correct |
164 ms |
1038600 KB |
Output is correct |
4 |
Correct |
149 ms |
1038736 KB |
Output is correct |
5 |
Correct |
174 ms |
1038676 KB |
Output is correct |
6 |
Correct |
158 ms |
1038672 KB |
Output is correct |
7 |
Correct |
168 ms |
1038676 KB |
Output is correct |
8 |
Correct |
150 ms |
1038848 KB |
Output is correct |
9 |
Correct |
166 ms |
1038672 KB |
Output is correct |
10 |
Correct |
144 ms |
1038632 KB |
Output is correct |
11 |
Correct |
147 ms |
1038704 KB |
Output is correct |
12 |
Correct |
145 ms |
1038672 KB |
Output is correct |
13 |
Correct |
146 ms |
1038672 KB |
Output is correct |
14 |
Correct |
143 ms |
1038676 KB |
Output is correct |
15 |
Correct |
150 ms |
1038772 KB |
Output is correct |
16 |
Correct |
146 ms |
1038556 KB |
Output is correct |
17 |
Correct |
145 ms |
1038600 KB |
Output is correct |
18 |
Correct |
150 ms |
1038560 KB |
Output is correct |
19 |
Correct |
145 ms |
1038556 KB |
Output is correct |
20 |
Correct |
144 ms |
1038788 KB |
Output is correct |
21 |
Correct |
153 ms |
1038572 KB |
Output is correct |
22 |
Correct |
152 ms |
1038852 KB |
Output is correct |
23 |
Correct |
144 ms |
1038732 KB |
Output is correct |
24 |
Correct |
143 ms |
1038676 KB |
Output is correct |
25 |
Correct |
144 ms |
1038596 KB |
Output is correct |
26 |
Correct |
158 ms |
1038872 KB |
Output is correct |
27 |
Correct |
149 ms |
1038672 KB |
Output is correct |
28 |
Correct |
153 ms |
1038572 KB |
Output is correct |
29 |
Correct |
145 ms |
1038716 KB |
Output is correct |
30 |
Correct |
147 ms |
1038644 KB |
Output is correct |
31 |
Correct |
143 ms |
1038680 KB |
Output is correct |
32 |
Correct |
145 ms |
1038672 KB |
Output is correct |
33 |
Correct |
159 ms |
1039052 KB |
Output is correct |
34 |
Correct |
143 ms |
1038684 KB |
Output is correct |
35 |
Correct |
148 ms |
1038580 KB |
Output is correct |
36 |
Correct |
143 ms |
1038788 KB |
Output is correct |
37 |
Correct |
147 ms |
1038676 KB |
Output is correct |
38 |
Correct |
146 ms |
1038560 KB |
Output is correct |
39 |
Correct |
146 ms |
1038676 KB |
Output is correct |
40 |
Correct |
149 ms |
1038768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
159 ms |
1038720 KB |
Output is correct |
2 |
Correct |
147 ms |
1038672 KB |
Output is correct |
3 |
Correct |
164 ms |
1038600 KB |
Output is correct |
4 |
Correct |
149 ms |
1038736 KB |
Output is correct |
5 |
Correct |
174 ms |
1038676 KB |
Output is correct |
6 |
Correct |
158 ms |
1038672 KB |
Output is correct |
7 |
Correct |
168 ms |
1038676 KB |
Output is correct |
8 |
Correct |
150 ms |
1038848 KB |
Output is correct |
9 |
Correct |
166 ms |
1038672 KB |
Output is correct |
10 |
Correct |
144 ms |
1038632 KB |
Output is correct |
11 |
Correct |
147 ms |
1038704 KB |
Output is correct |
12 |
Correct |
145 ms |
1038672 KB |
Output is correct |
13 |
Correct |
146 ms |
1038672 KB |
Output is correct |
14 |
Correct |
143 ms |
1038676 KB |
Output is correct |
15 |
Correct |
150 ms |
1038772 KB |
Output is correct |
16 |
Correct |
146 ms |
1038556 KB |
Output is correct |
17 |
Correct |
145 ms |
1038600 KB |
Output is correct |
18 |
Correct |
150 ms |
1038560 KB |
Output is correct |
19 |
Correct |
145 ms |
1038556 KB |
Output is correct |
20 |
Correct |
144 ms |
1038788 KB |
Output is correct |
21 |
Correct |
153 ms |
1038572 KB |
Output is correct |
22 |
Correct |
152 ms |
1038852 KB |
Output is correct |
23 |
Correct |
144 ms |
1038732 KB |
Output is correct |
24 |
Correct |
143 ms |
1038676 KB |
Output is correct |
25 |
Correct |
144 ms |
1038596 KB |
Output is correct |
26 |
Correct |
158 ms |
1038872 KB |
Output is correct |
27 |
Correct |
149 ms |
1038672 KB |
Output is correct |
28 |
Correct |
153 ms |
1038572 KB |
Output is correct |
29 |
Correct |
145 ms |
1038716 KB |
Output is correct |
30 |
Correct |
147 ms |
1038644 KB |
Output is correct |
31 |
Correct |
143 ms |
1038680 KB |
Output is correct |
32 |
Correct |
145 ms |
1038672 KB |
Output is correct |
33 |
Correct |
159 ms |
1039052 KB |
Output is correct |
34 |
Correct |
143 ms |
1038684 KB |
Output is correct |
35 |
Correct |
148 ms |
1038580 KB |
Output is correct |
36 |
Correct |
143 ms |
1038788 KB |
Output is correct |
37 |
Correct |
147 ms |
1038676 KB |
Output is correct |
38 |
Correct |
146 ms |
1038560 KB |
Output is correct |
39 |
Correct |
146 ms |
1038676 KB |
Output is correct |
40 |
Correct |
149 ms |
1038768 KB |
Output is correct |
41 |
Correct |
166 ms |
1038672 KB |
Output is correct |
42 |
Correct |
145 ms |
1038676 KB |
Output is correct |
43 |
Correct |
145 ms |
1038672 KB |
Output is correct |
44 |
Correct |
147 ms |
1038592 KB |
Output is correct |
45 |
Correct |
148 ms |
1038676 KB |
Output is correct |
46 |
Correct |
152 ms |
1038676 KB |
Output is correct |
47 |
Correct |
157 ms |
1038792 KB |
Output is correct |
48 |
Correct |
150 ms |
1038732 KB |
Output is correct |
49 |
Correct |
158 ms |
1038672 KB |
Output is correct |
50 |
Correct |
157 ms |
1038676 KB |
Output is correct |
51 |
Correct |
157 ms |
1039044 KB |
Output is correct |
52 |
Correct |
158 ms |
1038796 KB |
Output is correct |
53 |
Correct |
151 ms |
1038672 KB |
Output is correct |
54 |
Correct |
158 ms |
1038676 KB |
Output is correct |
55 |
Correct |
157 ms |
1038720 KB |
Output is correct |
56 |
Correct |
150 ms |
1038572 KB |
Output is correct |
57 |
Correct |
165 ms |
1038784 KB |
Output is correct |
58 |
Correct |
156 ms |
1038672 KB |
Output is correct |
59 |
Correct |
154 ms |
1038776 KB |
Output is correct |
60 |
Correct |
152 ms |
1038680 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2536 ms |
1038956 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
337 ms |
1038776 KB |
Output is correct |
2 |
Correct |
193 ms |
1038676 KB |
Output is correct |
3 |
Correct |
197 ms |
1038892 KB |
Output is correct |
4 |
Correct |
199 ms |
1038932 KB |
Output is correct |
5 |
Correct |
364 ms |
1038672 KB |
Output is correct |
6 |
Correct |
699 ms |
1038856 KB |
Output is correct |
7 |
Correct |
1240 ms |
1038804 KB |
Output is correct |
8 |
Correct |
2001 ms |
1038808 KB |
Output is correct |
9 |
Execution timed out |
2537 ms |
1038676 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |