답안 #1030685

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1030685 2024-07-22T08:34:18 Z Otalp Let's Win the Election (JOI22_ho_t3) C++14
21 / 100
251 ms 512 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define pii pair<int, int>
#define ff first
#define ss second
#define ld long double
#define pb push_back


pii a[200100];

bool cmp(pii a, pii b){
    return a.ss < b.ss;
}

 

void solve(){
    int n, k;
    cin>>n>>k;
    int dmx = 0;
    for(int i=1; i<=n; i++){
        cin>>a[i].ff>>a[i].ss;
        if(a[i].ss == -1){
            a[i].ss = 1e9;
        }
    }
    sort(a + 1, a + 1 + n, cmp);
    //for(int i=1; i<=n; i++) cout<<a[i].ff<<' '<<a[i].ss<<'\n';
    ld ans = 1e18;
    for(ld D=1; D<=k+1; D++){
        vector<int> d;
        ld res = 0;
        int m = k - D+1;
        int ok = 1;
        for(int i=1; i<=D-1; i++){
            d.pb(i);
            res += 1.0 * a[i].ss / i;
        }
        multiset<pii> dd;
        for(int i=D; i<=n; i++){
            dd.insert({a[i].ff, i});
            if(dd.size() > m){
                dd.erase(--(dd.end()));
            }
        }
        for(pii x: dd){
            res += x.ff / D;
        }
        //cout<<"________________\n";
        //cout<<D<<'\n';
            //cout<<res<<'\n';
            //for(auto x: dd) cout<<x.ff<<' '<<x.ss<<'\n';
            //for(int x: d) cout<<x<<' ';
            //cout<<'\n';
        ans = min(ans, res);
        for(int i=D; i<=n; i++){
            //cout<<i<<'\n';
            pair<ld, int> mn = {1e18, -1};
            res += a[i].ss * 1.0 / (D);
            int mx = (dd.size() ?(*dd.begin()).ss :0);
            if(dd.find({a[i].ff, i}) != dd.end()){
                mx = 0;
                dd.erase({a[i].ff, i});
                res -= a[i].ff / D;
            }

            
            ld g = 0;
            d.pb(i);
            for(int i=d.size() - 1; i>=0; i--){
                int j = d[i];
                mn = min(mn, {-a[j].ss * 1.0 / (i + 1) + g - a[mx].ff/D + a[j].ff/D, j});
                if(i > 0)g += -a[j].ss * 1.0 / (i + 1) + a[j].ss * 1.0 / i;
            }
            res += mn.ff;
            dd.insert({a[mn.ss].ff, mn.ss});
            if(dd.size() > m) dd.erase(--(dd.end()));
            vector<int> dg;
            for(int x: d){
                if(x != mn.ss) dg.pb(x);
            }
            d = dg;
            ans = min(ans, res);
        }
    }
    cout<<fixed<<setprecision(6)<<ans;
}
 
 
signed main(){
    solve();
}

Compilation message

Main.cpp: In function 'void solve()':
Main.cpp:45:26: warning: comparison of integer expressions of different signedness: 'std::multiset<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   45 |             if(dd.size() > m){
      |                ~~~~~~~~~~^~~
Main.cpp:80:26: warning: comparison of integer expressions of different signedness: 'std::multiset<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   80 |             if(dd.size() > m) dd.erase(--(dd.end()));
      |                ~~~~~~~~~~^~~
Main.cpp:37:13: warning: unused variable 'ok' [-Wunused-variable]
   37 |         int ok = 1;
      |             ^~
Main.cpp:23:9: warning: unused variable 'dmx' [-Wunused-variable]
   23 |     int dmx = 0;
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 9 ms 348 KB Output is correct
6 Correct 37 ms 460 KB Output is correct
7 Correct 108 ms 348 KB Output is correct
8 Correct 171 ms 344 KB Output is correct
9 Correct 198 ms 348 KB Output is correct
10 Correct 144 ms 344 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 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 9 ms 348 KB Output is correct
6 Correct 37 ms 460 KB Output is correct
7 Correct 108 ms 348 KB Output is correct
8 Correct 171 ms 344 KB Output is correct
9 Correct 198 ms 348 KB Output is correct
10 Correct 144 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 54 ms 348 KB Output is correct
13 Correct 46 ms 348 KB Output is correct
14 Correct 47 ms 348 KB Output is correct
15 Correct 153 ms 348 KB Output is correct
16 Correct 152 ms 452 KB Output is correct
17 Correct 157 ms 348 KB Output is correct
18 Correct 188 ms 344 KB Output is correct
19 Correct 209 ms 348 KB Output is correct
20 Correct 214 ms 344 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 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 Incorrect 0 ms 348 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 Incorrect 0 ms 348 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 Incorrect 0 ms 348 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 211 ms 472 KB Output is correct
2 Correct 231 ms 348 KB Output is correct
3 Correct 205 ms 348 KB Output is correct
4 Correct 251 ms 348 KB Output is correct
5 Correct 219 ms 512 KB Output is correct
6 Correct 202 ms 456 KB Output is correct
7 Correct 230 ms 348 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 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 9 ms 348 KB Output is correct
6 Correct 37 ms 460 KB Output is correct
7 Correct 108 ms 348 KB Output is correct
8 Correct 171 ms 344 KB Output is correct
9 Correct 198 ms 348 KB Output is correct
10 Correct 144 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 54 ms 348 KB Output is correct
13 Correct 46 ms 348 KB Output is correct
14 Correct 47 ms 348 KB Output is correct
15 Correct 153 ms 348 KB Output is correct
16 Correct 152 ms 452 KB Output is correct
17 Correct 157 ms 348 KB Output is correct
18 Correct 188 ms 344 KB Output is correct
19 Correct 209 ms 348 KB Output is correct
20 Correct 214 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 Incorrect 0 ms 348 KB Output isn't correct
30 Halted 0 ms 0 KB -