//JOI 2022 Final Round
#include<bits/stdc++.h>
using namespace std;
//#define double long double
const int N=505;
double dp[N][N][N];
const double INF=1e9+7;
void init(){
for(int i=0; i<N; i++){
for(int j=0; j<N; j++){
for(int k=0; k<N; k++){
dp[i][j][k] = INF;
}
}
}
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, k;
cin >> n >> k;
vector<int> a(n);
vector<int> b(n);
for(int i=0; i<n; i++){
cin >> a[i] >> b[i];
}
vector<int> sorted(n);
iota(sorted.begin(), sorted.end(), 0);
sort(sorted.begin(), sorted.end(), [&](int i, int j){
if(b[i]==-1) return false;
if(b[j]==-1) return true;
return b[i]<b[j];
});
cout.precision(300);
init();
dp[0][0][0]=(double)0;
for(int i=0; i<n; i++){
int ind=sorted[i];
//cout << i << ": " << ind << "\n";
for(int x=0; x<=i+1; x++){
for(int y=0; y<=x; y++){
dp[i+1][x][y] = dp[i][x][y];
if(0<x){
dp[i+1][x][y] = min(dp[i+1][x][y], dp[i][x-1][y] + (double)a[ind]/(double)(y+1));
}
if(0<y && b[ind]!=-1){
dp[i+1][x][y] = min(dp[i+1][x][y], dp[i][x-1][y-1] + (double)b[ind]/(double)y);
//cout << dp[i][x-1][y-1] << "\n";
}
//cout << i << " " << x << " " << y << ": " << dp[i+1][x][y] << "\n";
}
}
}
double ans=INF;
for(int y=0; y<=n; y++){
ans = min(ans, dp[n][k][y]);
}
cout << ans << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
357 ms |
1008300 KB |
Output is correct |
2 |
Correct |
339 ms |
1008348 KB |
Output is correct |
3 |
Correct |
351 ms |
1008316 KB |
Output is correct |
4 |
Correct |
344 ms |
1008400 KB |
Output is correct |
5 |
Correct |
470 ms |
1008428 KB |
Output is correct |
6 |
Correct |
379 ms |
1008408 KB |
Output is correct |
7 |
Correct |
382 ms |
1008544 KB |
Output is correct |
8 |
Correct |
421 ms |
1008436 KB |
Output is correct |
9 |
Correct |
420 ms |
1008448 KB |
Output is correct |
10 |
Correct |
376 ms |
1008344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
357 ms |
1008300 KB |
Output is correct |
2 |
Correct |
339 ms |
1008348 KB |
Output is correct |
3 |
Correct |
351 ms |
1008316 KB |
Output is correct |
4 |
Correct |
344 ms |
1008400 KB |
Output is correct |
5 |
Correct |
470 ms |
1008428 KB |
Output is correct |
6 |
Correct |
379 ms |
1008408 KB |
Output is correct |
7 |
Correct |
382 ms |
1008544 KB |
Output is correct |
8 |
Correct |
421 ms |
1008436 KB |
Output is correct |
9 |
Correct |
420 ms |
1008448 KB |
Output is correct |
10 |
Correct |
376 ms |
1008344 KB |
Output is correct |
11 |
Correct |
343 ms |
1008412 KB |
Output is correct |
12 |
Correct |
412 ms |
1008428 KB |
Output is correct |
13 |
Correct |
399 ms |
1008336 KB |
Output is correct |
14 |
Correct |
373 ms |
1008332 KB |
Output is correct |
15 |
Correct |
422 ms |
1008588 KB |
Output is correct |
16 |
Correct |
402 ms |
1008432 KB |
Output is correct |
17 |
Correct |
383 ms |
1008428 KB |
Output is correct |
18 |
Correct |
407 ms |
1008428 KB |
Output is correct |
19 |
Correct |
385 ms |
1008484 KB |
Output is correct |
20 |
Correct |
405 ms |
1008352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
327 ms |
1008448 KB |
Output is correct |
2 |
Correct |
326 ms |
1008448 KB |
Output is correct |
3 |
Correct |
359 ms |
1008364 KB |
Output is correct |
4 |
Correct |
321 ms |
1008348 KB |
Output is correct |
5 |
Correct |
327 ms |
1008400 KB |
Output is correct |
6 |
Correct |
360 ms |
1008336 KB |
Output is correct |
7 |
Correct |
323 ms |
1008500 KB |
Output is correct |
8 |
Correct |
349 ms |
1008312 KB |
Output is correct |
9 |
Incorrect |
324 ms |
1008420 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
327 ms |
1008448 KB |
Output is correct |
2 |
Correct |
326 ms |
1008448 KB |
Output is correct |
3 |
Correct |
359 ms |
1008364 KB |
Output is correct |
4 |
Correct |
321 ms |
1008348 KB |
Output is correct |
5 |
Correct |
327 ms |
1008400 KB |
Output is correct |
6 |
Correct |
360 ms |
1008336 KB |
Output is correct |
7 |
Correct |
323 ms |
1008500 KB |
Output is correct |
8 |
Correct |
349 ms |
1008312 KB |
Output is correct |
9 |
Incorrect |
324 ms |
1008420 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
327 ms |
1008448 KB |
Output is correct |
2 |
Correct |
326 ms |
1008448 KB |
Output is correct |
3 |
Correct |
359 ms |
1008364 KB |
Output is correct |
4 |
Correct |
321 ms |
1008348 KB |
Output is correct |
5 |
Correct |
327 ms |
1008400 KB |
Output is correct |
6 |
Correct |
360 ms |
1008336 KB |
Output is correct |
7 |
Correct |
323 ms |
1008500 KB |
Output is correct |
8 |
Correct |
349 ms |
1008312 KB |
Output is correct |
9 |
Incorrect |
324 ms |
1008420 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
421 ms |
1008436 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
357 ms |
1008300 KB |
Output is correct |
2 |
Correct |
339 ms |
1008348 KB |
Output is correct |
3 |
Correct |
351 ms |
1008316 KB |
Output is correct |
4 |
Correct |
344 ms |
1008400 KB |
Output is correct |
5 |
Correct |
470 ms |
1008428 KB |
Output is correct |
6 |
Correct |
379 ms |
1008408 KB |
Output is correct |
7 |
Correct |
382 ms |
1008544 KB |
Output is correct |
8 |
Correct |
421 ms |
1008436 KB |
Output is correct |
9 |
Correct |
420 ms |
1008448 KB |
Output is correct |
10 |
Correct |
376 ms |
1008344 KB |
Output is correct |
11 |
Correct |
343 ms |
1008412 KB |
Output is correct |
12 |
Correct |
412 ms |
1008428 KB |
Output is correct |
13 |
Correct |
399 ms |
1008336 KB |
Output is correct |
14 |
Correct |
373 ms |
1008332 KB |
Output is correct |
15 |
Correct |
422 ms |
1008588 KB |
Output is correct |
16 |
Correct |
402 ms |
1008432 KB |
Output is correct |
17 |
Correct |
383 ms |
1008428 KB |
Output is correct |
18 |
Correct |
407 ms |
1008428 KB |
Output is correct |
19 |
Correct |
385 ms |
1008484 KB |
Output is correct |
20 |
Correct |
405 ms |
1008352 KB |
Output is correct |
21 |
Correct |
327 ms |
1008448 KB |
Output is correct |
22 |
Correct |
326 ms |
1008448 KB |
Output is correct |
23 |
Correct |
359 ms |
1008364 KB |
Output is correct |
24 |
Correct |
321 ms |
1008348 KB |
Output is correct |
25 |
Correct |
327 ms |
1008400 KB |
Output is correct |
26 |
Correct |
360 ms |
1008336 KB |
Output is correct |
27 |
Correct |
323 ms |
1008500 KB |
Output is correct |
28 |
Correct |
349 ms |
1008312 KB |
Output is correct |
29 |
Incorrect |
324 ms |
1008420 KB |
Output isn't correct |
30 |
Halted |
0 ms |
0 KB |
- |