Submission #593688

# Submission time Handle Problem Language Result Execution time Memory
593688 2022-07-11T13:45:45 Z welleyth Let's Win the Election (JOI22_ho_t3) C++17
0 / 100
1 ms 340 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#define int long long
#define mp make_pair
#define pb push_back

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx2")

constexpr int INF = (int)2e18;
constexpr int N = (int)4e5 + 111;
constexpr int md = (int)1e9+7;
constexpr int mdPower = (int)1e9+7 - 1;
constexpr double eps = 1e-7;

typedef __int128 _uint;
typedef long long ll;

mt19937_64 rnd(time(nullptr));

void add(int& a,int b){
    a += b; if(a >= md) a -= md;
}
void sub(int& a,int b){
    a -= b; while(a < 0) a += md;
}
void add(__int128& a,int b){
    a += b;
}
void sub(__int128& a,int b){
    a -= b;
}

int bpow(int a,int b){
    if(b == 0)
        return 1;
    if(b % 2 == 0){
        int t = bpow(a,b>>1);
        return 1ll*t*t%md;
    }
    return 1ll * a*bpow(a,b-1) % md;
}

int inv(int a){
    return bpow(a,md-2);
}

//int fac[N],invfac[N];
//
//void init(){
//    fac[0] = 1;
//    for(int i = 1; i < N; i++){
//        fac[i] = (fac[i-1] * i) % md;
//    }
//    invfac[N-1] = inv(fac[N-1]);
//    for(int i = N-2; i >= 0; i--){
//        invfac[i] = (invfac[i+1] * (i+1))%md;
//    }
//    return;
//}
//
//int C(int n,int k){
//    if(k > n)
//        return 0;
//    return fac[n] * invfac[k] % md * invfac[n-k] % md;
//}
//
//int A(int n,int k){
//    if(k > n)
//        return 0;
//    return fac[n] * invfac[n-k] % md;
//

void solve(){
    int n;
    cin >> n;
    int k;
    cin >> k;
    int a[n],b[n];
    vector<pair<int,int>> v;
    for(int i = 0; i < n; i++){
        cin >> a[i] >> b[i];
        v.pb(mp(a[i],b[i]));
    }
    sort(v.begin(),v.end());
    for(int i = 0; i < n; i++){
        a[i] = v[i].first;
        b[i] = v[i].second;
    }

    long double ans = INF;
    v.clear();

    for(int cnt2 = 0; cnt2 <= n; cnt2++){ /// dyplomats from right
        int r = cnt2;
        vector<int> y;
        for(int i = k; i < n; i++){
            if(b[i] != -1)
                y.pb(b[i]);
        }
        if(y.size() < r)
            continue;
        sort(y.begin(),y.end());
        int s = 0;
//        int c[1111] = {};
        v.clear();
        for(int i = 0; i < n; i++){
            if(a[i] > a[k-r])
                break;
            if(b[i] != -1){
                v.pb(mp(b[i],-a[i]));
            }
            if(i < k-r)
                s += a[i];
        }
        sort(v.begin(),v.end());
        for(int cnt = cnt2; cnt <= n; cnt++){ /// total number of dyplomats
            int l = cnt - cnt2;
            if(v.size() < l)
                continue;
            int sum = s;
            long double t = 0;
            vector<int> p;
            for(int i = 0; i < l; i++){
                p.pb(v[i].first);
                sum += v[i].second;
            }
            for(int i = 0; i < r; i++){
                p.pb(y[i]);
            }
            sort(p.begin(),p.end());
            if(p.size() != cnt)
                continue;
            for(int i = 0; i < p.size(); i++){
                t += 1.0 * p[i] / (i+1);
            }
            ans = min(ans,t + 1.0 * sum / (cnt+1));
//            cerr << cnt << " " << cnt2 << " " << sum << " " << t << "\n";
//            cerr << "cur = " << t + 1.0 * sum / (cnt+1) << "\n";
        }
    }

    cout << fixed << setprecision(10) << ans << "\n";

    return;
}

signed main(){
    ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
    int tests = 1;
//    cin >> tests;
    for(int test = 1; test <= tests; test++){
//        cerr << "test = " << test << "\n";
        solve();
    }
    return 0;
}
/**

**/

Compilation message

Main.cpp: In function 'void solve()':
Main.cpp:106:21: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
  106 |         if(y.size() < r)
      |            ~~~~~~~~~^~~
Main.cpp:124:25: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
  124 |             if(v.size() < l)
      |                ~~~~~~~~~^~~
Main.cpp:137:25: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
  137 |             if(p.size() != cnt)
      |                ~~~~~~~~~^~~~~~
Main.cpp:139:30: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  139 |             for(int i = 0; i < p.size(); i++){
      |                            ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Incorrect 1 ms 212 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Incorrect 1 ms 212 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Incorrect 1 ms 212 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -