답안 #1016224

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1016224 2024-07-07T14:22:20 Z ReLice Let's Win the Election (JOI22_ho_t3) C++14
100 / 100
1782 ms 9048 KB
#include <bits/stdc++.h>
#define ll long long
#define str string
#define ins insert
#define ld long double
#define pb push_back
#define pf push_front
#define pof pop_front()
#define pob pop_back()
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define fr first
#define sc second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define sz size()
#define vll vector<ll>
#define bc back()
#define arr array
#define pll vector<pair<ll,ll>>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>
template<class S,class T>
bool chmin(S &a,const T &b) {
	return a>b?(a=b)==b:false;
}
template<class S,class T>
bool chmax(S &a,const T &b) {
	return a<b?(a=b)==b:false;
}
//void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
void start(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
const ll inf=1e9;
const ll mod=1e9+7;
const ll N=1e3+7;
const ld eps=1e-9;

ld dp[N][N];
void solve(){
    ll i,j;
    ll n,k;
    cin>>n>>k;
    pll v(n);
    for(i=0;i<n;i++){
        cin>>v[i].sc>>v[i].fr;
        if(v[i].fr==-1)v[i].fr=inf;
    }
    sort(all(v));
    ll a[n+5],b[n+5];
    for(i=1;i<=n;i++){
        a[i]=v[i-1].sc;
        b[i]=v[i-1].fr;
    }
    ld ans=0;
    ll suf[n+5];;
    vll vv;
    for(i=1;i<=n;i++)vv.pb(a[i]);
    sort(all(vv));
    for(i=0;i<k;i++)ans+=vv[i];
    for(ll m=1;m<=k;m++){
        for(i=0;i<=n;i++){
            for(j=0;j<=n;j++)dp[i][j]=inf;
        }
        dp[0][0]=0;
        for(i=1;i<=k;i++){
            for(j=0;j<=min(i,m);j++){

                if(j && b[i]<inf) chmin( dp[i][j] , dp[i-1][j-1] + (ld)b[i]/(ld)j);
                chmin(dp[i][j],dp[i-1][j]+(ld)a[i]/(ld)(m+1));

                if(j==m){
                    vll v;
                    for(ll q=i+1;q<=n;q++)v.pb(a[q]);
                    sort(all(v));

                    ll sum=0;
                    for(ll q=0;q<k-i;q++) sum+=v[q];
                    chmin(ans,dp[i][j]+(ld)sum/(ld)(m+1));
                }
            }
        }
    }
    cout<<fixed<<setprecision(15)<<ans<<endl;

}
signed main(){
    start();
    ll t=1;
    //cin>>t;
    while(t--) solve();
    return 0;
}
/*
3 1 5
2 2
3 2
2 2
3 2
10


*/

Compilation message

Main.cpp: In function 'void solve()':
Main.cpp:63:8: warning: unused variable 'suf' [-Wunused-variable]
   63 |     ll suf[n+5];;
      |        ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 69 ms 8804 KB Output is correct
6 Correct 186 ms 8804 KB Output is correct
7 Correct 432 ms 8808 KB Output is correct
8 Correct 707 ms 8796 KB Output is correct
9 Correct 1071 ms 8804 KB Output is correct
10 Correct 645 ms 8804 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 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 69 ms 8804 KB Output is correct
6 Correct 186 ms 8804 KB Output is correct
7 Correct 432 ms 8808 KB Output is correct
8 Correct 707 ms 8796 KB Output is correct
9 Correct 1071 ms 8804 KB Output is correct
10 Correct 645 ms 8804 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 258 ms 8804 KB Output is correct
13 Correct 325 ms 9040 KB Output is correct
14 Correct 275 ms 8792 KB Output is correct
15 Correct 768 ms 8800 KB Output is correct
16 Correct 882 ms 8800 KB Output is correct
17 Correct 730 ms 9048 KB Output is correct
18 Correct 1338 ms 8792 KB Output is correct
19 Correct 1259 ms 8792 KB Output is correct
20 Correct 1042 ms 9044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 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 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 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 0 ms 348 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2516 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2512 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2516 KB Output is correct
29 Correct 0 ms 2396 KB Output is correct
30 Correct 1 ms 2512 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 0 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 0 ms 2396 KB Output is correct
35 Correct 0 ms 2396 KB Output is correct
36 Correct 1 ms 2396 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 1 ms 2396 KB Output is correct
40 Correct 1 ms 2392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 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 0 ms 348 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2516 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2512 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2516 KB Output is correct
29 Correct 0 ms 2396 KB Output is correct
30 Correct 1 ms 2512 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 0 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 0 ms 2396 KB Output is correct
35 Correct 0 ms 2396 KB Output is correct
36 Correct 1 ms 2396 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 1 ms 2396 KB Output is correct
40 Correct 1 ms 2392 KB Output is correct
41 Correct 1 ms 2516 KB Output is correct
42 Correct 2 ms 2512 KB Output is correct
43 Correct 3 ms 2396 KB Output is correct
44 Correct 3 ms 2580 KB Output is correct
45 Correct 4 ms 2396 KB Output is correct
46 Correct 4 ms 2396 KB Output is correct
47 Correct 7 ms 2396 KB Output is correct
48 Correct 6 ms 2392 KB Output is correct
49 Correct 8 ms 2508 KB Output is correct
50 Correct 8 ms 2392 KB Output is correct
51 Correct 12 ms 2396 KB Output is correct
52 Correct 11 ms 2396 KB Output is correct
53 Correct 6 ms 2396 KB Output is correct
54 Correct 6 ms 2584 KB Output is correct
55 Correct 6 ms 2396 KB Output is correct
56 Correct 6 ms 2516 KB Output is correct
57 Correct 6 ms 2396 KB Output is correct
58 Correct 6 ms 2580 KB Output is correct
59 Correct 6 ms 2396 KB Output is correct
60 Correct 5 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1681 ms 8804 KB Output is correct
2 Correct 1663 ms 8796 KB Output is correct
3 Correct 1696 ms 8796 KB Output is correct
4 Correct 1643 ms 8796 KB Output is correct
5 Correct 1782 ms 8792 KB Output is correct
6 Correct 1746 ms 8796 KB Output is correct
7 Correct 1538 ms 8796 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 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 69 ms 8804 KB Output is correct
6 Correct 186 ms 8804 KB Output is correct
7 Correct 432 ms 8808 KB Output is correct
8 Correct 707 ms 8796 KB Output is correct
9 Correct 1071 ms 8804 KB Output is correct
10 Correct 645 ms 8804 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 258 ms 8804 KB Output is correct
13 Correct 325 ms 9040 KB Output is correct
14 Correct 275 ms 8792 KB Output is correct
15 Correct 768 ms 8800 KB Output is correct
16 Correct 882 ms 8800 KB Output is correct
17 Correct 730 ms 9048 KB Output is correct
18 Correct 1338 ms 8792 KB Output is correct
19 Correct 1259 ms 8792 KB Output is correct
20 Correct 1042 ms 9044 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 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 0 ms 348 KB Output is correct
36 Correct 1 ms 2396 KB Output is correct
37 Correct 0 ms 2396 KB Output is correct
38 Correct 0 ms 2396 KB Output is correct
39 Correct 1 ms 2396 KB Output is correct
40 Correct 0 ms 2396 KB Output is correct
41 Correct 1 ms 2396 KB Output is correct
42 Correct 1 ms 2396 KB Output is correct
43 Correct 1 ms 2516 KB Output is correct
44 Correct 1 ms 2396 KB Output is correct
45 Correct 1 ms 2396 KB Output is correct
46 Correct 1 ms 2512 KB Output is correct
47 Correct 1 ms 2396 KB Output is correct
48 Correct 1 ms 2516 KB Output is correct
49 Correct 0 ms 2396 KB Output is correct
50 Correct 1 ms 2512 KB Output is correct
51 Correct 1 ms 2396 KB Output is correct
52 Correct 0 ms 2396 KB Output is correct
53 Correct 1 ms 2396 KB Output is correct
54 Correct 0 ms 2396 KB Output is correct
55 Correct 0 ms 2396 KB Output is correct
56 Correct 1 ms 2396 KB Output is correct
57 Correct 1 ms 2396 KB Output is correct
58 Correct 1 ms 2396 KB Output is correct
59 Correct 1 ms 2396 KB Output is correct
60 Correct 1 ms 2392 KB Output is correct
61 Correct 1 ms 2516 KB Output is correct
62 Correct 2 ms 2512 KB Output is correct
63 Correct 3 ms 2396 KB Output is correct
64 Correct 3 ms 2580 KB Output is correct
65 Correct 4 ms 2396 KB Output is correct
66 Correct 4 ms 2396 KB Output is correct
67 Correct 7 ms 2396 KB Output is correct
68 Correct 6 ms 2392 KB Output is correct
69 Correct 8 ms 2508 KB Output is correct
70 Correct 8 ms 2392 KB Output is correct
71 Correct 12 ms 2396 KB Output is correct
72 Correct 11 ms 2396 KB Output is correct
73 Correct 6 ms 2396 KB Output is correct
74 Correct 6 ms 2584 KB Output is correct
75 Correct 6 ms 2396 KB Output is correct
76 Correct 6 ms 2516 KB Output is correct
77 Correct 6 ms 2396 KB Output is correct
78 Correct 6 ms 2580 KB Output is correct
79 Correct 6 ms 2396 KB Output is correct
80 Correct 5 ms 2396 KB Output is correct
81 Correct 1681 ms 8804 KB Output is correct
82 Correct 1663 ms 8796 KB Output is correct
83 Correct 1696 ms 8796 KB Output is correct
84 Correct 1643 ms 8796 KB Output is correct
85 Correct 1782 ms 8792 KB Output is correct
86 Correct 1746 ms 8796 KB Output is correct
87 Correct 1538 ms 8796 KB Output is correct
88 Correct 84 ms 8652 KB Output is correct
89 Correct 86 ms 8796 KB Output is correct
90 Correct 244 ms 8796 KB Output is correct
91 Correct 274 ms 8804 KB Output is correct
92 Correct 633 ms 8804 KB Output is correct
93 Correct 678 ms 8804 KB Output is correct
94 Correct 1173 ms 8804 KB Output is correct
95 Correct 1161 ms 8804 KB Output is correct
96 Correct 1480 ms 8808 KB Output is correct
97 Correct 1492 ms 8792 KB Output is correct
98 Correct 957 ms 8792 KB Output is correct
99 Correct 1036 ms 8804 KB Output is correct
100 Correct 1018 ms 8796 KB Output is correct
101 Correct 958 ms 8796 KB Output is correct
102 Correct 901 ms 8792 KB Output is correct
103 Correct 897 ms 8796 KB Output is correct
104 Correct 884 ms 8796 KB Output is correct
105 Correct 666 ms 8796 KB Output is correct