Submission #863841

# Submission time Handle Problem Language Result Execution time Memory
863841 2023-10-21T08:56:35 Z prairie2022 Let's Win the Election (JOI22_ho_t3) C++17
33 / 100
382 ms 600 KB
#include<bits/stdc++.h>
typedef long double ld;
#define fastio cin.tie(0), cout.tie(0), ios::sync_with_stdio(0);
using namespace std;

#define F first 
#define S second

int main(){
    fastio
    const int big = 1e6;
    int n, k;
    ld ans = big;
    cin >> n >> k;
    vector<pair<int, int>> ba(n);
    for(int i=0; i<n; i++){
        cin >> ba[i].S >> ba[i].F;
        if(ba[i].F==-1) ba[i].F = big;
    }
    sort(ba.begin(), ba.end());
    if(n>20){
        for(int i=0; i<=k; i++){
            if(i && ba[i-1].F==big) break;
            ld tmp = 0;
            for(int j=0; j<i; j++)
                tmp += ((ld)ba[j].F)/(1+j);
            vector<int> rem(n-i);
            for(int j=i; j<n; j++) rem[j-i] = ba[j].S;
            sort(rem.begin(), rem.end());
            int hr = 0;
            for(int j=0; j<k-i; j++) hr += rem[j];
            tmp += ((ld)hr)/(1+i);
            ans = min(ans, tmp);
        }
        cout << fixed << setprecision(6) << ans << '\n';
        return 0;
    }
    for(int mask = 0; mask<(1<<n); mask++){
        bool flag = 0;
        vector<int> b, a;
        for(int i=0; i<n; i++){
            if(mask&(1<<i)){
                if(ba[i].F==big){
                    flag = 1;
                    break;
                }
                b.push_back(ba[i].F);
            }
            else a.push_back(ba[i].S);
        }
        if(flag || b.size()>=k) break;
        sort(a.begin(), a.end());
        ld tmp = 0;
        for(int i=0; i<b.size(); i++)
            tmp += ((ld)b[i])/(1+i);
        for(int i=0; i<k-b.size(); i++){
            tmp += ((ld)a[i])/(1+b.size());
        }
        ans = min(tmp, ans);
    }
    cout << fixed << setprecision(6) << ans << '\n';
    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:51:28: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   51 |         if(flag || b.size()>=k) break;
      |                    ~~~~~~~~^~~
Main.cpp:54:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |         for(int i=0; i<b.size(); i++)
      |                      ~^~~~~~~~~
Main.cpp:56:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |         for(int i=0; i<k-b.size(); i++){
      |                      ~^~~~~~~~~~~
# Verdict Execution time Memory 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 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory 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 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 2 ms 600 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 2 ms 456 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory 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 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 0 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
# Verdict Execution time Memory 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 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 0 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 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 388 KB Output is correct
19 Correct 3 ms 348 KB Output is correct
20 Correct 3 ms 348 KB Output is correct
21 Correct 3 ms 348 KB Output is correct
22 Correct 7 ms 448 KB Output is correct
23 Correct 6 ms 348 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 382 ms 600 KB Output is correct
26 Correct 95 ms 348 KB Output is correct
27 Correct 3 ms 348 KB Output is correct
28 Correct 6 ms 348 KB Output is correct
29 Correct 3 ms 348 KB Output is correct
30 Correct 7 ms 452 KB Output is correct
31 Correct 4 ms 344 KB Output is correct
32 Correct 6 ms 344 KB Output is correct
33 Correct 3 ms 348 KB Output is correct
34 Correct 3 ms 348 KB Output is correct
35 Correct 6 ms 348 KB Output is correct
36 Correct 3 ms 348 KB Output is correct
37 Correct 6 ms 348 KB Output is correct
38 Correct 3 ms 348 KB Output is correct
39 Correct 5 ms 452 KB Output is correct
40 Correct 3 ms 348 KB Output is correct
# Verdict Execution time Memory 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 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 0 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 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 388 KB Output is correct
19 Correct 3 ms 348 KB Output is correct
20 Correct 3 ms 348 KB Output is correct
21 Correct 3 ms 348 KB Output is correct
22 Correct 7 ms 448 KB Output is correct
23 Correct 6 ms 348 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 382 ms 600 KB Output is correct
26 Correct 95 ms 348 KB Output is correct
27 Correct 3 ms 348 KB Output is correct
28 Correct 6 ms 348 KB Output is correct
29 Correct 3 ms 348 KB Output is correct
30 Correct 7 ms 452 KB Output is correct
31 Correct 4 ms 344 KB Output is correct
32 Correct 6 ms 344 KB Output is correct
33 Correct 3 ms 348 KB Output is correct
34 Correct 3 ms 348 KB Output is correct
35 Correct 6 ms 348 KB Output is correct
36 Correct 3 ms 348 KB Output is correct
37 Correct 6 ms 348 KB Output is correct
38 Correct 3 ms 348 KB Output is correct
39 Correct 5 ms 452 KB Output is correct
40 Correct 3 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Incorrect 0 ms 344 KB Output isn't correct
44 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 2 ms 600 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 2 ms 456 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 0 ms 348 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 0 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 0 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 0 ms 388 KB Output is correct
39 Correct 3 ms 348 KB Output is correct
40 Correct 3 ms 348 KB Output is correct
41 Correct 3 ms 348 KB Output is correct
42 Correct 7 ms 448 KB Output is correct
43 Correct 6 ms 348 KB Output is correct
44 Correct 2 ms 348 KB Output is correct
45 Correct 382 ms 600 KB Output is correct
46 Correct 95 ms 348 KB Output is correct
47 Correct 3 ms 348 KB Output is correct
48 Correct 6 ms 348 KB Output is correct
49 Correct 3 ms 348 KB Output is correct
50 Correct 7 ms 452 KB Output is correct
51 Correct 4 ms 344 KB Output is correct
52 Correct 6 ms 344 KB Output is correct
53 Correct 3 ms 348 KB Output is correct
54 Correct 3 ms 348 KB Output is correct
55 Correct 6 ms 348 KB Output is correct
56 Correct 3 ms 348 KB Output is correct
57 Correct 6 ms 348 KB Output is correct
58 Correct 3 ms 348 KB Output is correct
59 Correct 5 ms 452 KB Output is correct
60 Correct 3 ms 348 KB Output is correct
61 Correct 0 ms 348 KB Output is correct
62 Correct 0 ms 348 KB Output is correct
63 Incorrect 0 ms 344 KB Output isn't correct
64 Halted 0 ms 0 KB -