답안 #916080

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
916080 2024-01-25T08:47:44 Z yeediot Let's Win the Election (JOI22_ho_t3) C++14
100 / 100
359 ms 4996 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define all(X) X.begin(),X.end()
#define chmax(a,b) a=max(a,b)
#define chmin(a,b) a=min(a,b)
#ifdef local
void setio(){freopen("/Users/iantsai/Library/Mobile Documents/com~apple~CloudDocs/cpp/Empty.md","r",stdin);}
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
void setio(){}
#define debug(x...)
#endif
bool cmp(pii a,pii b){
    if(a.S!=b.S)return a.S<b.S;
    return a.F<b.F;
}
const int inf=2e12;
signed main(){
    cout<<fixed<<setprecision(10);
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    setio();
    int n,k;
    cin>>n>>k;
    vector<pii>vec;
    vec.pb({0,0});
    for(int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        vec.pb({a,b});
        if(b==-1){
            vec[i+1].S=inf;
        }
    }
    sort(all(vec),cmp);
    vector<vector<int>>suf(n+2,vector<int>(k+2,0));
    for(int i=1;i<=k;i++){
        multiset<int>st;
        int sum=0;
        for(int j=n;j>=1;j--){
            st.insert(vec[j].F);
            sum+=vec[j].F;
            if((int)(st.size())>i){
                sum-=*prev(st.end());
                st.erase(prev(st.end()));
            }
            if((int)(st.size())==i){
                suf[j][i]=sum;
            }
        }
    }
    double ans=inf;
    for(int p=0;p<=k;p++){
        vector<vector<double>>dp(n+1,vector<double>(p+1,inf));
        dp[0][0]=0;
        for(int i=0;i<=k;i++){
            for(int j=0;j<=p;j++){
                if(j and i)dp[i][j]=dp[i-1][j-1]+(double)vec[i].S/j;
                if(i)dp[i][j]=min(dp[i][j],dp[i-1][j]+(double)vec[i].F/(p+1));
                //cout<<i<<' '<<j<<' '<<dp[i][j]<<' '<<vec[i].F<<'\n';
                if(j==p){
                    chmin(ans,dp[i][j]+(double)suf[i+1][k-i]/(p+1));
                    //cout<<i<<' '<<j<<' '<<ans<<' '<<dp[i][j]<<'\n';
                }
            }
        }
        //cout<<ans<<'\n';
    }
    cout<<ans<<'\n';
}




# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 3 ms 904 KB Output is correct
6 Correct 15 ms 1668 KB Output is correct
7 Correct 64 ms 2884 KB Output is correct
8 Correct 164 ms 3820 KB Output is correct
9 Correct 344 ms 4792 KB Output is correct
10 Correct 135 ms 3588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 3 ms 904 KB Output is correct
6 Correct 15 ms 1668 KB Output is correct
7 Correct 64 ms 2884 KB Output is correct
8 Correct 164 ms 3820 KB Output is correct
9 Correct 344 ms 4792 KB Output is correct
10 Correct 135 ms 3588 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 21 ms 1880 KB Output is correct
13 Correct 21 ms 1892 KB Output is correct
14 Correct 26 ms 2128 KB Output is correct
15 Correct 139 ms 3660 KB Output is correct
16 Correct 139 ms 3448 KB Output is correct
17 Correct 143 ms 3608 KB Output is correct
18 Correct 340 ms 4900 KB Output is correct
19 Correct 335 ms 4732 KB Output is correct
20 Correct 339 ms 4800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 600 KB Output is correct
10 Correct 0 ms 452 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 600 KB Output is correct
10 Correct 0 ms 452 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 600 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 452 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 344 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 600 KB Output is correct
10 Correct 0 ms 452 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 600 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 452 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 344 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 1 ms 604 KB Output is correct
48 Correct 2 ms 572 KB Output is correct
49 Correct 2 ms 856 KB Output is correct
50 Correct 2 ms 600 KB Output is correct
51 Correct 3 ms 604 KB Output is correct
52 Correct 3 ms 604 KB Output is correct
53 Correct 2 ms 604 KB Output is correct
54 Correct 1 ms 604 KB Output is correct
55 Correct 1 ms 604 KB Output is correct
56 Correct 1 ms 604 KB Output is correct
57 Correct 2 ms 604 KB Output is correct
58 Correct 2 ms 600 KB Output is correct
59 Correct 2 ms 604 KB Output is correct
60 Correct 2 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 337 ms 4996 KB Output is correct
2 Correct 331 ms 4716 KB Output is correct
3 Correct 359 ms 4932 KB Output is correct
4 Correct 329 ms 4708 KB Output is correct
5 Correct 337 ms 4748 KB Output is correct
6 Correct 331 ms 4692 KB Output is correct
7 Correct 340 ms 4676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 3 ms 904 KB Output is correct
6 Correct 15 ms 1668 KB Output is correct
7 Correct 64 ms 2884 KB Output is correct
8 Correct 164 ms 3820 KB Output is correct
9 Correct 344 ms 4792 KB Output is correct
10 Correct 135 ms 3588 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 21 ms 1880 KB Output is correct
13 Correct 21 ms 1892 KB Output is correct
14 Correct 26 ms 2128 KB Output is correct
15 Correct 139 ms 3660 KB Output is correct
16 Correct 139 ms 3448 KB Output is correct
17 Correct 143 ms 3608 KB Output is correct
18 Correct 340 ms 4900 KB Output is correct
19 Correct 335 ms 4732 KB Output is correct
20 Correct 339 ms 4800 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 600 KB Output is correct
30 Correct 0 ms 452 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 0 ms 344 KB Output is correct
37 Correct 0 ms 600 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 1 ms 344 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 1 ms 344 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 344 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 1 ms 348 KB Output is correct
53 Correct 1 ms 344 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 0 ms 348 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 0 ms 452 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 0 ms 344 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 1 ms 348 KB Output is correct
62 Correct 1 ms 348 KB Output is correct
63 Correct 1 ms 348 KB Output is correct
64 Correct 1 ms 348 KB Output is correct
65 Correct 1 ms 348 KB Output is correct
66 Correct 1 ms 348 KB Output is correct
67 Correct 1 ms 604 KB Output is correct
68 Correct 2 ms 572 KB Output is correct
69 Correct 2 ms 856 KB Output is correct
70 Correct 2 ms 600 KB Output is correct
71 Correct 3 ms 604 KB Output is correct
72 Correct 3 ms 604 KB Output is correct
73 Correct 2 ms 604 KB Output is correct
74 Correct 1 ms 604 KB Output is correct
75 Correct 1 ms 604 KB Output is correct
76 Correct 1 ms 604 KB Output is correct
77 Correct 2 ms 604 KB Output is correct
78 Correct 2 ms 600 KB Output is correct
79 Correct 2 ms 604 KB Output is correct
80 Correct 2 ms 604 KB Output is correct
81 Correct 337 ms 4996 KB Output is correct
82 Correct 331 ms 4716 KB Output is correct
83 Correct 359 ms 4932 KB Output is correct
84 Correct 329 ms 4708 KB Output is correct
85 Correct 337 ms 4748 KB Output is correct
86 Correct 331 ms 4692 KB Output is correct
87 Correct 340 ms 4676 KB Output is correct
88 Correct 3 ms 892 KB Output is correct
89 Correct 3 ms 904 KB Output is correct
90 Correct 14 ms 1684 KB Output is correct
91 Correct 15 ms 1676 KB Output is correct
92 Correct 63 ms 2828 KB Output is correct
93 Correct 63 ms 2660 KB Output is correct
94 Correct 167 ms 3620 KB Output is correct
95 Correct 164 ms 3752 KB Output is correct
96 Correct 253 ms 4252 KB Output is correct
97 Correct 254 ms 4256 KB Output is correct
98 Correct 133 ms 3452 KB Output is correct
99 Correct 135 ms 3520 KB Output is correct
100 Correct 136 ms 3456 KB Output is correct
101 Correct 152 ms 3424 KB Output is correct
102 Correct 141 ms 3612 KB Output is correct
103 Correct 146 ms 3464 KB Output is correct
104 Correct 143 ms 3440 KB Output is correct
105 Correct 138 ms 3536 KB Output is correct