Submission #824355

# Submission time Handle Problem Language Result Execution time Memory
824355 2023-08-14T04:04:58 Z PoonYaPat Let's Win the Election (JOI22_ho_t3) C++14
56 / 100
2500 ms 4324 KB
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef pair<ld,ld> pii;

int n,k;
ld ans=1e9,a[505],b[505],dp[505][505];
vector<pii> v;

void check(ld want) {
    for (int i=0; i<=n; ++i) for (int j=0; j<=n; ++j) dp[i][j]=1e9;
    dp[0][0]=0;

    for (int i=0; i<=k; ++i) {
        if (i) {
            for (int j=0; j<=want; ++j) {
                if (j!=0 && b[i]!=1e9) dp[i][j]=min(dp[i][j],dp[i-1][j-1]+b[i]/j); //choose B
                if (j!=want) dp[i][j]=min(dp[i][j],dp[i-1][j]+a[i]/(want+1)); //choose A
            }
        }

        ld sum=0;
        priority_queue<ld> q;
        for (int j=i+1; j<=n; ++j) {
            q.push(a[j]);
            sum+=a[j];
            if (q.size()>k-i) {
                sum-=q.top();
                q.pop();
            }
        }

        if (dp[i][(int)(want)]<1000000) ans=min(ans,dp[i][(int)(want)]+sum/(want+1));
    }
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n>>k;
    for (int i=0; i<n; ++i) {
        ld a,b; cin>>a>>b;
        if (b!=-1) v.push_back(pii(b,a));
        else v.push_back(pii(1e9,a));
    }
    sort(v.begin(),v.end());
    for (int i=1; i<=n; ++i) a[i]=v[i-1].second, b[i]=v[i-1].first;
    for (int i=0; i<=k; ++i) check(i);
    cout<<setprecision(15)<<ans;
}

Compilation message

Main.cpp: In function 'void check(ld)':
Main.cpp:27:25: warning: comparison of integer expressions of different signedness: 'std::priority_queue<long double>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   27 |             if (q.size()>k-i) {
      |                 ~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 113 ms 4320 KB Output is correct
6 Correct 510 ms 4324 KB Output is correct
7 Correct 1628 ms 4320 KB Output is correct
8 Execution timed out 2566 ms 4308 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 113 ms 4320 KB Output is correct
6 Correct 510 ms 4324 KB Output is correct
7 Correct 1628 ms 4320 KB Output is correct
8 Execution timed out 2566 ms 4308 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 324 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 324 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 324 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 332 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 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 328 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 324 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 324 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 324 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 332 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 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 328 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 324 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 2 ms 852 KB Output is correct
42 Correct 2 ms 852 KB Output is correct
43 Correct 6 ms 852 KB Output is correct
44 Correct 6 ms 852 KB Output is correct
45 Correct 14 ms 852 KB Output is correct
46 Correct 16 ms 928 KB Output is correct
47 Correct 20 ms 852 KB Output is correct
48 Correct 19 ms 852 KB Output is correct
49 Correct 27 ms 852 KB Output is correct
50 Correct 27 ms 852 KB Output is correct
51 Correct 26 ms 852 KB Output is correct
52 Correct 25 ms 928 KB Output is correct
53 Correct 20 ms 836 KB Output is correct
54 Correct 20 ms 852 KB Output is correct
55 Correct 20 ms 836 KB Output is correct
56 Correct 18 ms 932 KB Output is correct
57 Correct 19 ms 852 KB Output is correct
58 Correct 24 ms 916 KB Output is correct
59 Correct 17 ms 852 KB Output is correct
60 Correct 17 ms 936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2560 ms 4308 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 113 ms 4320 KB Output is correct
6 Correct 510 ms 4324 KB Output is correct
7 Correct 1628 ms 4320 KB Output is correct
8 Execution timed out 2566 ms 4308 KB Time limit exceeded
9 Halted 0 ms 0 KB -