답안 #734588

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
734588 2023-05-02T16:46:39 Z 1075508020060209tc Let's Win the Election (JOI22_ho_t3) C++14
100 / 100
190 ms 4312 KB
#include<bits/stdc++.h>
using namespace std;
//#define double long double
int n;int K;
int M;
pair<int,int>ar[200005];
double ans;

double dp[510][510];
int srtsf[510][510];
int srtps[510][510];
bool cmp(pair<int,int>i,pair<int,int>j){
if(i.second<j.second){return 1;}
if(i.second>j.second){return 0;}
if(i.first>j.first){return 1;}
return 0;
}

double solve(int m){

for(int i=0;i<=n;i++){
    for(int j=0;j<=n;j++){
        dp[i][j]=1000000;
    }
}
dp[0][0]=0;
dp[1][0]=(double)ar[1].first/(double)(m+1);
dp[1][1]=ar[1].second;

for(int i=1;i<=K-1;i++){
    for(int j=0;j<=i;j++){
        //if(dp[i][j]>500000){continue;}
        dp[i+1][j]=min(dp[i+1][j],dp[i][j]+(double)ar[i+1].first/(double)(m+1));
        dp[i+1][j+1]=min(dp[i+1][j+1],dp[i][j]+(double)ar[i+1].second/(double)(j+1));
    }
}
double ret=dp[K][m];
//cout<<fixed<<setprecision(6)<<ret<<"  ";
for(int i=K-1;i>=m;i--){

    ret=min(ret,dp[i][m]+(double)srtps[i+1][i+1+K-i-1]/(double)(m+1));
}
//cout<<fixed<<setprecision(6)<<ret<<endl;
return ret;
}


signed main(){
cin>>n>>K;
M=0;
for(int i=1;i<=n;i++){
    cin>>ar[i].first>>ar[i].second;
    if(ar[i].second==-1){
        ar[i].second=200000;
    }else{
        M++;
    }
}

sort(ar+1,ar+n+1,cmp);
/*
cout<<endl;
for(int i=1;i<=n;i++){
    cout<<ar[i].first<<" "<<ar[i].second<<endl;
}
cout<<endl;
*/
for(int i=1;i<=n;i++){

    for(int j=i;j<=n;j++){
        srtsf[i][j]=ar[j].first;
        //srtps[i][j]=srtsf[i][j]+srtps[i][j-1];
    }
    sort(srtsf[i]+i,srtsf[i]+n+1);
    for(int j=i;j<=n;j++){
        srtps[i][j]=srtsf[i][j]+srtps[i][j-1];
    }
}
/*
for(int i=1;i<=n;i++){

    for(int j=1;j<=n;j++){
        cout<<srtsf[i][j]<<" ";
    }cout<<endl;

}
*/



ans=5000000;
for(int i=0;i<=min(K,M);i++){
    ans=min(ans,solve(i));
}
cout<<fixed<<setprecision(6)<<ans<<endl;




/*


double l=0;double r=500000;
for(int ttt=0;ttt<90;ttt++){
    double mi=(l+r)/2;
    if(ok(mi)){
        l=mi;
    }else{
        r=mi;
    }
}

cout<<fixed<<setprecision(6)<<l<<endl;


*/

}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 4 ms 4308 KB Output is correct
6 Correct 4 ms 4308 KB Output is correct
7 Correct 4 ms 4308 KB Output is correct
8 Correct 4 ms 4308 KB Output is correct
9 Correct 4 ms 4308 KB Output is correct
10 Correct 3 ms 4308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 4 ms 4308 KB Output is correct
6 Correct 4 ms 4308 KB Output is correct
7 Correct 4 ms 4308 KB Output is correct
8 Correct 4 ms 4308 KB Output is correct
9 Correct 4 ms 4308 KB Output is correct
10 Correct 3 ms 4308 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 20 ms 4312 KB Output is correct
13 Correct 22 ms 4268 KB Output is correct
14 Correct 15 ms 4308 KB Output is correct
15 Correct 74 ms 4308 KB Output is correct
16 Correct 65 ms 4308 KB Output is correct
17 Correct 28 ms 4308 KB Output is correct
18 Correct 163 ms 4308 KB Output is correct
19 Correct 103 ms 4308 KB Output is correct
20 Correct 36 ms 4312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 304 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 308 KB Output is correct
14 Correct 0 ms 304 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 304 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 308 KB Output is correct
14 Correct 0 ms 304 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 436 KB Output is correct
22 Correct 1 ms 436 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 436 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 1 ms 468 KB Output is correct
35 Correct 1 ms 468 KB Output is correct
36 Correct 1 ms 468 KB Output is correct
37 Correct 1 ms 432 KB Output is correct
38 Correct 1 ms 468 KB Output is correct
39 Correct 1 ms 468 KB Output is correct
40 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 304 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 308 KB Output is correct
14 Correct 0 ms 304 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 436 KB Output is correct
22 Correct 1 ms 436 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 436 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 1 ms 468 KB Output is correct
35 Correct 1 ms 468 KB Output is correct
36 Correct 1 ms 468 KB Output is correct
37 Correct 1 ms 432 KB Output is correct
38 Correct 1 ms 468 KB Output is correct
39 Correct 1 ms 468 KB Output is correct
40 Correct 1 ms 468 KB Output is correct
41 Correct 1 ms 1108 KB Output is correct
42 Correct 1 ms 1108 KB Output is correct
43 Correct 1 ms 1108 KB Output is correct
44 Correct 1 ms 1108 KB Output is correct
45 Correct 2 ms 1076 KB Output is correct
46 Correct 2 ms 1108 KB Output is correct
47 Correct 2 ms 1108 KB Output is correct
48 Correct 2 ms 1108 KB Output is correct
49 Correct 2 ms 1108 KB Output is correct
50 Correct 2 ms 1072 KB Output is correct
51 Correct 3 ms 1108 KB Output is correct
52 Correct 2 ms 1108 KB Output is correct
53 Correct 2 ms 1072 KB Output is correct
54 Correct 2 ms 1076 KB Output is correct
55 Correct 2 ms 1080 KB Output is correct
56 Correct 2 ms 1108 KB Output is correct
57 Correct 2 ms 1080 KB Output is correct
58 Correct 2 ms 1108 KB Output is correct
59 Correct 2 ms 1108 KB Output is correct
60 Correct 2 ms 1108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 164 ms 4296 KB Output is correct
2 Correct 169 ms 4292 KB Output is correct
3 Correct 170 ms 4288 KB Output is correct
4 Correct 171 ms 4312 KB Output is correct
5 Correct 174 ms 4308 KB Output is correct
6 Correct 190 ms 4308 KB Output is correct
7 Correct 187 ms 4308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 4 ms 4308 KB Output is correct
6 Correct 4 ms 4308 KB Output is correct
7 Correct 4 ms 4308 KB Output is correct
8 Correct 4 ms 4308 KB Output is correct
9 Correct 4 ms 4308 KB Output is correct
10 Correct 3 ms 4308 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 20 ms 4312 KB Output is correct
13 Correct 22 ms 4268 KB Output is correct
14 Correct 15 ms 4308 KB Output is correct
15 Correct 74 ms 4308 KB Output is correct
16 Correct 65 ms 4308 KB Output is correct
17 Correct 28 ms 4308 KB Output is correct
18 Correct 163 ms 4308 KB Output is correct
19 Correct 103 ms 4308 KB Output is correct
20 Correct 36 ms 4312 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 308 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 304 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 304 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 1 ms 308 KB Output is correct
34 Correct 0 ms 304 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 468 KB Output is correct
37 Correct 1 ms 468 KB Output is correct
38 Correct 1 ms 468 KB Output is correct
39 Correct 1 ms 468 KB Output is correct
40 Correct 1 ms 468 KB Output is correct
41 Correct 1 ms 436 KB Output is correct
42 Correct 1 ms 436 KB Output is correct
43 Correct 1 ms 468 KB Output is correct
44 Correct 1 ms 436 KB Output is correct
45 Correct 1 ms 468 KB Output is correct
46 Correct 1 ms 468 KB Output is correct
47 Correct 1 ms 468 KB Output is correct
48 Correct 1 ms 468 KB Output is correct
49 Correct 1 ms 468 KB Output is correct
50 Correct 1 ms 468 KB Output is correct
51 Correct 1 ms 468 KB Output is correct
52 Correct 1 ms 468 KB Output is correct
53 Correct 1 ms 468 KB Output is correct
54 Correct 1 ms 468 KB Output is correct
55 Correct 1 ms 468 KB Output is correct
56 Correct 1 ms 468 KB Output is correct
57 Correct 1 ms 432 KB Output is correct
58 Correct 1 ms 468 KB Output is correct
59 Correct 1 ms 468 KB Output is correct
60 Correct 1 ms 468 KB Output is correct
61 Correct 1 ms 1108 KB Output is correct
62 Correct 1 ms 1108 KB Output is correct
63 Correct 1 ms 1108 KB Output is correct
64 Correct 1 ms 1108 KB Output is correct
65 Correct 2 ms 1076 KB Output is correct
66 Correct 2 ms 1108 KB Output is correct
67 Correct 2 ms 1108 KB Output is correct
68 Correct 2 ms 1108 KB Output is correct
69 Correct 2 ms 1108 KB Output is correct
70 Correct 2 ms 1072 KB Output is correct
71 Correct 3 ms 1108 KB Output is correct
72 Correct 2 ms 1108 KB Output is correct
73 Correct 2 ms 1072 KB Output is correct
74 Correct 2 ms 1076 KB Output is correct
75 Correct 2 ms 1080 KB Output is correct
76 Correct 2 ms 1108 KB Output is correct
77 Correct 2 ms 1080 KB Output is correct
78 Correct 2 ms 1108 KB Output is correct
79 Correct 2 ms 1108 KB Output is correct
80 Correct 2 ms 1108 KB Output is correct
81 Correct 164 ms 4296 KB Output is correct
82 Correct 169 ms 4292 KB Output is correct
83 Correct 170 ms 4288 KB Output is correct
84 Correct 171 ms 4312 KB Output is correct
85 Correct 174 ms 4308 KB Output is correct
86 Correct 190 ms 4308 KB Output is correct
87 Correct 187 ms 4308 KB Output is correct
88 Correct 13 ms 4308 KB Output is correct
89 Correct 12 ms 4276 KB Output is correct
90 Correct 21 ms 4308 KB Output is correct
91 Correct 20 ms 4308 KB Output is correct
92 Correct 45 ms 4308 KB Output is correct
93 Correct 44 ms 4308 KB Output is correct
94 Correct 93 ms 4308 KB Output is correct
95 Correct 110 ms 4308 KB Output is correct
96 Correct 156 ms 4308 KB Output is correct
97 Correct 153 ms 4308 KB Output is correct
98 Correct 85 ms 4308 KB Output is correct
99 Correct 83 ms 4300 KB Output is correct
100 Correct 83 ms 4308 KB Output is correct
101 Correct 92 ms 4308 KB Output is correct
102 Correct 99 ms 4308 KB Output is correct
103 Correct 81 ms 4268 KB Output is correct
104 Correct 87 ms 4304 KB Output is correct
105 Correct 81 ms 4308 KB Output is correct