답안 #534258

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
534258 2022-03-08T02:48:12 Z Cookie197 Let's Win the Election (JOI22_ho_t3) C++14
33 / 100
372 ms 392 KB
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<set>
#include<iomanip>
using namespace std;
#define ll long long
#define pii pair<int,int> 
#define mp make_pair
#define endl "\n"
#define out(x) cout << #x << " = " << x << endl
#define outp(x) cout << #x << ".first = " << x.first << "  " << #x << ".second = " << x.second << endl
#pragma GCC optimize("Ofast")
#define lll __int128

// enumerate the num of collaborators, from 0 to k-1
// it is optimal to collect all collaborators first, then give speeches

int n,k;
pii arr[505];
bool subtask1 = true, subtask2 = true;
signed main(){
    ios::sync_with_stdio(false); cin.tie(0);
    cin>>n>>k;
    for (int i=0;i<n;i++) {
        cin>>arr[i].first>>arr[i].second;
        if (arr[i].second != -1) subtask1 = false;
        if (arr[i].second != -1 && arr[i].second != arr[i].first) subtask2 = false;
    }

    if (subtask1){
        sort(arr,arr+n);
        int ans = 0;
        for (int i=0;i<k;i++) ans+=arr[i].first;
        cout<<ans<<endl;
        return 0;
    }
    
    if (subtask2){
        multiset<int> c,s,cc,ss;
        for (int i=0;i<n;i++) {
            if (arr[i].second==-1) ss.insert(arr[i].first);
            else cc.insert(arr[i].first);
        }


        double best = 1e9;
        for (int num=0;num<k;num++){
            c=cc,s=ss;
            int people = 1;
            double now = 0;
            if (num > c.size()) break;
            for (int i=0;i<num;i++){
                now += 1.0 * *(c.begin()) / people;
                people++;
                c.erase(c.begin());
            }
            for (int u:c) s.insert(u);

            for (int i=0;i<k-num;i++){
                now += 1.0 * *(s.begin()) / people;
                s.erase(s.begin());
            }
            best = min(best, now);
        }
        cout<<fixed<<setprecision(9)<<best<<endl;
        return 0;
    }

    if (n<=20){
        double best = 1e9;
        int ok[505];
        vector<int> collab,speech;
        for (int bit=0;bit<(1<<n);bit++){ // choose collaborators
            if (__builtin_popcount(bit) >= k) continue;
            double now = 0;
            collab.clear();
            for (int i=0;i<n;i++) ok[i] = false;
            int cnt = 0;
            for (int i=0;i<n;i++) if ((1<<i) & bit) if (arr[i].second != -1) collab.push_back(arr[i].second), ok[i] = true, cnt++;
            
            sort(collab.begin(),collab.end());
            int people = 1;
            for (double d:collab){
                now += d/people;
                people++;
            }

            speech.clear();
            for (int i=0;i<n;i++) if (!ok[i]) speech.push_back(arr[i].first);

            sort(speech.begin(),speech.end());
            for (int i=0;i<k-cnt;i++) now += 1.0 * speech[i] / people;

            best = min(best, now);
        }
        cout<<fixed<<setprecision(9)<<best<<endl;
        return 0;
    }


    

}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:53:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::multiset<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |             if (num > c.size()) break;
      |                 ~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 316 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 316 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 10 ms 392 KB Output is correct
13 Correct 7 ms 372 KB Output is correct
14 Correct 3 ms 332 KB Output is correct
15 Correct 21 ms 388 KB Output is correct
16 Correct 10 ms 332 KB Output is correct
17 Correct 3 ms 332 KB Output is correct
18 Correct 24 ms 332 KB Output is correct
19 Correct 12 ms 376 KB Output is correct
20 Correct 3 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 292 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 312 KB Output is correct
14 Correct 1 ms 324 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 292 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 312 KB Output is correct
14 Correct 1 ms 324 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 3 ms 312 KB Output is correct
17 Correct 95 ms 296 KB Output is correct
18 Correct 88 ms 324 KB Output is correct
19 Correct 328 ms 292 KB Output is correct
20 Correct 299 ms 292 KB Output is correct
21 Correct 285 ms 296 KB Output is correct
22 Correct 329 ms 300 KB Output is correct
23 Correct 337 ms 300 KB Output is correct
24 Correct 276 ms 300 KB Output is correct
25 Correct 369 ms 300 KB Output is correct
26 Correct 372 ms 296 KB Output is correct
27 Correct 289 ms 292 KB Output is correct
28 Correct 295 ms 296 KB Output is correct
29 Correct 282 ms 204 KB Output is correct
30 Correct 302 ms 292 KB Output is correct
31 Correct 268 ms 304 KB Output is correct
32 Correct 289 ms 204 KB Output is correct
33 Correct 260 ms 292 KB Output is correct
34 Correct 271 ms 204 KB Output is correct
35 Correct 309 ms 292 KB Output is correct
36 Correct 287 ms 300 KB Output is correct
37 Correct 289 ms 292 KB Output is correct
38 Correct 259 ms 296 KB Output is correct
39 Correct 313 ms 292 KB Output is correct
40 Correct 270 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 292 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 312 KB Output is correct
14 Correct 1 ms 324 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 3 ms 312 KB Output is correct
17 Correct 95 ms 296 KB Output is correct
18 Correct 88 ms 324 KB Output is correct
19 Correct 328 ms 292 KB Output is correct
20 Correct 299 ms 292 KB Output is correct
21 Correct 285 ms 296 KB Output is correct
22 Correct 329 ms 300 KB Output is correct
23 Correct 337 ms 300 KB Output is correct
24 Correct 276 ms 300 KB Output is correct
25 Correct 369 ms 300 KB Output is correct
26 Correct 372 ms 296 KB Output is correct
27 Correct 289 ms 292 KB Output is correct
28 Correct 295 ms 296 KB Output is correct
29 Correct 282 ms 204 KB Output is correct
30 Correct 302 ms 292 KB Output is correct
31 Correct 268 ms 304 KB Output is correct
32 Correct 289 ms 204 KB Output is correct
33 Correct 260 ms 292 KB Output is correct
34 Correct 271 ms 204 KB Output is correct
35 Correct 309 ms 292 KB Output is correct
36 Correct 287 ms 300 KB Output is correct
37 Correct 289 ms 292 KB Output is correct
38 Correct 259 ms 296 KB Output is correct
39 Correct 313 ms 292 KB Output is correct
40 Correct 270 ms 204 KB Output is correct
41 Incorrect 1 ms 204 KB Output isn't correct
42 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 316 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 10 ms 392 KB Output is correct
13 Correct 7 ms 372 KB Output is correct
14 Correct 3 ms 332 KB Output is correct
15 Correct 21 ms 388 KB Output is correct
16 Correct 10 ms 332 KB Output is correct
17 Correct 3 ms 332 KB Output is correct
18 Correct 24 ms 332 KB Output is correct
19 Correct 12 ms 376 KB Output is correct
20 Correct 3 ms 332 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 0 ms 204 KB Output is correct
29 Correct 1 ms 292 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 312 KB Output is correct
34 Correct 1 ms 324 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 3 ms 312 KB Output is correct
37 Correct 95 ms 296 KB Output is correct
38 Correct 88 ms 324 KB Output is correct
39 Correct 328 ms 292 KB Output is correct
40 Correct 299 ms 292 KB Output is correct
41 Correct 285 ms 296 KB Output is correct
42 Correct 329 ms 300 KB Output is correct
43 Correct 337 ms 300 KB Output is correct
44 Correct 276 ms 300 KB Output is correct
45 Correct 369 ms 300 KB Output is correct
46 Correct 372 ms 296 KB Output is correct
47 Correct 289 ms 292 KB Output is correct
48 Correct 295 ms 296 KB Output is correct
49 Correct 282 ms 204 KB Output is correct
50 Correct 302 ms 292 KB Output is correct
51 Correct 268 ms 304 KB Output is correct
52 Correct 289 ms 204 KB Output is correct
53 Correct 260 ms 292 KB Output is correct
54 Correct 271 ms 204 KB Output is correct
55 Correct 309 ms 292 KB Output is correct
56 Correct 287 ms 300 KB Output is correct
57 Correct 289 ms 292 KB Output is correct
58 Correct 259 ms 296 KB Output is correct
59 Correct 313 ms 292 KB Output is correct
60 Correct 270 ms 204 KB Output is correct
61 Incorrect 1 ms 204 KB Output isn't correct
62 Halted 0 ms 0 KB -