답안 #534375

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
534375 2022-03-08T06:14:10 Z PixelCat Let's Win the Election (JOI22_ho_t3) C++14
100 / 100
75 ms 4344 KB
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Forr(i,a,b) for(int i=a;i>=b;i--)
#define F first
#define S second
#define sz(x) ((int)x.size())
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define INF (LL)(9e18)
#define int LL
using namespace std;
using LL=long long;
using pii=pair<int,int>;

const int MAXN=510;

double p[MAXN];
int a[MAXN];
int b[MAXN];
int mn[MAXN][MAXN];
double dp[MAXN][MAXN];

int32_t main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    // OAO
    int n,k; cin>>n>>k;
    {
        vector<pii> v(n);
        for(auto &i:v) cin>>i.F>>i.S;
        sort(all(v),[](const pii &pa,const pii &pb){
            if(pa.S==-1) return false;
            if(pb.S==-1) return true;
            return pa.S<pb.S;
        });
        For(i,0,n-1){
            a[i+1]=v[i].F;
            b[i+1]=v[i].S;
        }
    }
    For(i,1,n) p[i]=1.0/i;
    For(i,0,n){
        priority_queue<int> pq;
        int sum=0;
        Forr(j,n,1){
            sum+=a[j];
            pq.emplace(a[j]);
            if(sz(pq)>i){
                sum-=pq.top();
                pq.pop();
            }
            mn[i][j]=sum;
        }
    }
    // For(i,0,n) For(j,1,n) cout<<mn[i][j]<<" \n"[j==n];
    For(i,0,n) For(j,0,n) dp[i][j]=INF;
    dp[0][0]=0;
    double ans=mn[k][1];
    For(nc,0,k-1){
        For(i,1,n) For(j,0,min(i,nc)){
            dp[i][j]=dp[i-1][j]+a[i]*p[nc+1];
            if(b[i]!=-1 && j){
                dp[i][j]=min(dp[i][j],dp[i-1][j-1]+b[i]*p[j]);
            }
            if(j==nc){
                ans=min(ans,dp[i][j]+mn[k-i][i+1]*p[nc+1]);
            }
        }
    }
    cout<<fixed<<setprecision(15);
    cout<<ans<<"\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 11 ms 4300 KB Output is correct
6 Correct 14 ms 4300 KB Output is correct
7 Correct 25 ms 4300 KB Output is correct
8 Correct 39 ms 4300 KB Output is correct
9 Correct 55 ms 4300 KB Output is correct
10 Correct 38 ms 4320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 11 ms 4300 KB Output is correct
6 Correct 14 ms 4300 KB Output is correct
7 Correct 25 ms 4300 KB Output is correct
8 Correct 39 ms 4300 KB Output is correct
9 Correct 55 ms 4300 KB Output is correct
10 Correct 38 ms 4320 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 16 ms 4300 KB Output is correct
13 Correct 16 ms 4340 KB Output is correct
14 Correct 21 ms 4224 KB Output is correct
15 Correct 39 ms 4300 KB Output is correct
16 Correct 39 ms 4300 KB Output is correct
17 Correct 35 ms 4300 KB Output is correct
18 Correct 65 ms 4336 KB Output is correct
19 Correct 64 ms 4284 KB Output is correct
20 Correct 59 ms 4252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 1 ms 320 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 1 ms 320 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 448 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 1 ms 448 KB Output is correct
20 Correct 1 ms 460 KB Output is correct
21 Correct 1 ms 452 KB Output is correct
22 Correct 1 ms 460 KB Output is correct
23 Correct 1 ms 460 KB Output is correct
24 Correct 1 ms 460 KB Output is correct
25 Correct 1 ms 460 KB Output is correct
26 Correct 1 ms 460 KB Output is correct
27 Correct 1 ms 448 KB Output is correct
28 Correct 1 ms 460 KB Output is correct
29 Correct 1 ms 448 KB Output is correct
30 Correct 1 ms 460 KB Output is correct
31 Correct 1 ms 460 KB Output is correct
32 Correct 1 ms 460 KB Output is correct
33 Correct 1 ms 460 KB Output is correct
34 Correct 1 ms 460 KB Output is correct
35 Correct 1 ms 460 KB Output is correct
36 Correct 1 ms 460 KB Output is correct
37 Correct 1 ms 408 KB Output is correct
38 Correct 1 ms 460 KB Output is correct
39 Correct 1 ms 460 KB Output is correct
40 Correct 1 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 1 ms 320 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 448 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 1 ms 448 KB Output is correct
20 Correct 1 ms 460 KB Output is correct
21 Correct 1 ms 452 KB Output is correct
22 Correct 1 ms 460 KB Output is correct
23 Correct 1 ms 460 KB Output is correct
24 Correct 1 ms 460 KB Output is correct
25 Correct 1 ms 460 KB Output is correct
26 Correct 1 ms 460 KB Output is correct
27 Correct 1 ms 448 KB Output is correct
28 Correct 1 ms 460 KB Output is correct
29 Correct 1 ms 448 KB Output is correct
30 Correct 1 ms 460 KB Output is correct
31 Correct 1 ms 460 KB Output is correct
32 Correct 1 ms 460 KB Output is correct
33 Correct 1 ms 460 KB Output is correct
34 Correct 1 ms 460 KB Output is correct
35 Correct 1 ms 460 KB Output is correct
36 Correct 1 ms 460 KB Output is correct
37 Correct 1 ms 408 KB Output is correct
38 Correct 1 ms 460 KB Output is correct
39 Correct 1 ms 460 KB Output is correct
40 Correct 1 ms 460 KB Output is correct
41 Correct 1 ms 1088 KB Output is correct
42 Correct 1 ms 1100 KB Output is correct
43 Correct 1 ms 1100 KB Output is correct
44 Correct 1 ms 1100 KB Output is correct
45 Correct 1 ms 1100 KB Output is correct
46 Correct 1 ms 1100 KB Output is correct
47 Correct 2 ms 1100 KB Output is correct
48 Correct 1 ms 1100 KB Output is correct
49 Correct 2 ms 1100 KB Output is correct
50 Correct 2 ms 1100 KB Output is correct
51 Correct 2 ms 1092 KB Output is correct
52 Correct 2 ms 1088 KB Output is correct
53 Correct 1 ms 1100 KB Output is correct
54 Correct 1 ms 1100 KB Output is correct
55 Correct 1 ms 1100 KB Output is correct
56 Correct 2 ms 1100 KB Output is correct
57 Correct 2 ms 1100 KB Output is correct
58 Correct 1 ms 1100 KB Output is correct
59 Correct 1 ms 1100 KB Output is correct
60 Correct 1 ms 1100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 4300 KB Output is correct
2 Correct 67 ms 4300 KB Output is correct
3 Correct 67 ms 4276 KB Output is correct
4 Correct 75 ms 4328 KB Output is correct
5 Correct 67 ms 4320 KB Output is correct
6 Correct 66 ms 4316 KB Output is correct
7 Correct 69 ms 4316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 11 ms 4300 KB Output is correct
6 Correct 14 ms 4300 KB Output is correct
7 Correct 25 ms 4300 KB Output is correct
8 Correct 39 ms 4300 KB Output is correct
9 Correct 55 ms 4300 KB Output is correct
10 Correct 38 ms 4320 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 16 ms 4300 KB Output is correct
13 Correct 16 ms 4340 KB Output is correct
14 Correct 21 ms 4224 KB Output is correct
15 Correct 39 ms 4300 KB Output is correct
16 Correct 39 ms 4300 KB Output is correct
17 Correct 35 ms 4300 KB Output is correct
18 Correct 65 ms 4336 KB Output is correct
19 Correct 64 ms 4284 KB Output is correct
20 Correct 59 ms 4252 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 0 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 0 ms 332 KB Output is correct
26 Correct 0 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 0 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 324 KB Output is correct
32 Correct 1 ms 320 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 448 KB Output is correct
37 Correct 1 ms 460 KB Output is correct
38 Correct 1 ms 460 KB Output is correct
39 Correct 1 ms 448 KB Output is correct
40 Correct 1 ms 460 KB Output is correct
41 Correct 1 ms 452 KB Output is correct
42 Correct 1 ms 460 KB Output is correct
43 Correct 1 ms 460 KB Output is correct
44 Correct 1 ms 460 KB Output is correct
45 Correct 1 ms 460 KB Output is correct
46 Correct 1 ms 460 KB Output is correct
47 Correct 1 ms 448 KB Output is correct
48 Correct 1 ms 460 KB Output is correct
49 Correct 1 ms 448 KB Output is correct
50 Correct 1 ms 460 KB Output is correct
51 Correct 1 ms 460 KB Output is correct
52 Correct 1 ms 460 KB Output is correct
53 Correct 1 ms 460 KB Output is correct
54 Correct 1 ms 460 KB Output is correct
55 Correct 1 ms 460 KB Output is correct
56 Correct 1 ms 460 KB Output is correct
57 Correct 1 ms 408 KB Output is correct
58 Correct 1 ms 460 KB Output is correct
59 Correct 1 ms 460 KB Output is correct
60 Correct 1 ms 460 KB Output is correct
61 Correct 1 ms 1088 KB Output is correct
62 Correct 1 ms 1100 KB Output is correct
63 Correct 1 ms 1100 KB Output is correct
64 Correct 1 ms 1100 KB Output is correct
65 Correct 1 ms 1100 KB Output is correct
66 Correct 1 ms 1100 KB Output is correct
67 Correct 2 ms 1100 KB Output is correct
68 Correct 1 ms 1100 KB Output is correct
69 Correct 2 ms 1100 KB Output is correct
70 Correct 2 ms 1100 KB Output is correct
71 Correct 2 ms 1092 KB Output is correct
72 Correct 2 ms 1088 KB Output is correct
73 Correct 1 ms 1100 KB Output is correct
74 Correct 1 ms 1100 KB Output is correct
75 Correct 1 ms 1100 KB Output is correct
76 Correct 2 ms 1100 KB Output is correct
77 Correct 2 ms 1100 KB Output is correct
78 Correct 1 ms 1100 KB Output is correct
79 Correct 1 ms 1100 KB Output is correct
80 Correct 1 ms 1100 KB Output is correct
81 Correct 64 ms 4300 KB Output is correct
82 Correct 67 ms 4300 KB Output is correct
83 Correct 67 ms 4276 KB Output is correct
84 Correct 75 ms 4328 KB Output is correct
85 Correct 67 ms 4320 KB Output is correct
86 Correct 66 ms 4316 KB Output is correct
87 Correct 69 ms 4316 KB Output is correct
88 Correct 11 ms 4300 KB Output is correct
89 Correct 10 ms 4300 KB Output is correct
90 Correct 19 ms 4268 KB Output is correct
91 Correct 14 ms 4300 KB Output is correct
92 Correct 26 ms 4288 KB Output is correct
93 Correct 27 ms 4344 KB Output is correct
94 Correct 47 ms 4332 KB Output is correct
95 Correct 48 ms 4300 KB Output is correct
96 Correct 60 ms 4300 KB Output is correct
97 Correct 54 ms 4284 KB Output is correct
98 Correct 38 ms 4316 KB Output is correct
99 Correct 38 ms 4324 KB Output is correct
100 Correct 40 ms 4320 KB Output is correct
101 Correct 45 ms 4324 KB Output is correct
102 Correct 42 ms 4328 KB Output is correct
103 Correct 43 ms 4320 KB Output is correct
104 Correct 44 ms 4336 KB Output is correct
105 Correct 44 ms 4324 KB Output is correct