Submission #529458

# Submission time Handle Problem Language Result Execution time Memory
529458 2022-02-23T03:28:16 Z wiwiho Let's Win the Election (JOI22_ho_t3) C++14
5 / 100
2500 ms 2168 KB
#include <bits/stdc++.h>

#define iter(a) a.begin(), a.end()
#define mp make_pair
#define F first
#define S second
#define eb emplace_back
#define lsort(a) sort(iter(a))
#define gsort(a) sort(iter(a), greater<>())

using namespace std;

typedef long long ll;
typedef double ld;

using pii = pair<int, int>;

ll iceil(ll a, ll b){
    return (a + b - 1) / b;
}

int n, k;
vector<int> a, b;

vector<ld> tans;

ld calc(int cnt){
    if(tans[cnt] != 1e99) return tans[cnt];

    vector<vector<ld>> dp(cnt + 1, vector<ld>(k + 1, 1e87));
    dp[0][0] = 0;

    for(int i = 1; i <= n; i++){
        for(int c1 = cnt; c1 >= 0; c1--){
            for(int c2 = k; c2 >= 0; c2--){
                if(dp[c1][c2] == 1e87) continue;
                if(c1 < cnt && b[i] != -1) dp[c1 + 1][c2] = min(dp[c1 + 1][c2], dp[c1][c2] + (ld)b[i] / (c1 + 1));
                if(c2 < k) dp[c1][c2 + 1] = min(dp[c1][c2 + 1], dp[c1][c2] + (ld)a[i] / (cnt + 1));
            }
        }
    }

    //cerr << "calc " << cnt << "  " << dp[cnt][k - cnt] << "\n";
    tans[cnt] = dp[cnt][k - cnt];
    return dp[cnt][k - cnt];
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> k;
    a.resize(n + 1);
    b.resize(n + 1);
    tans.resize(k + 1, 1e99);

    vector<pii> tmp(n + 1);
    int c = 0;
    for(int i = 1; i <= n; i++){
        cin >> tmp[i].F >> tmp[i].S;
        if(tmp[i].S != -1) c++;
    }
    sort(tmp.begin() + 1, tmp.end(), [&](pii a, pii b){ return a.S < b.S; });

    for(int i = 1; i <= n; i++) a[i] = tmp[i].F, b[i] = tmp[i].S;

    int l = 0, r = c;
    while(l < r){
        int mid = (l + r) / 2;
        if(calc(mid) >= calc(mid + 1)) l = mid + 1;
        else r = mid;
    }

    cout << fixed << setprecision(20) << calc(l) << "\n";

    return 0;
}
# Verdict Execution time Memory 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 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory 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 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Incorrect 0 ms 204 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1918 ms 1760 KB Output is correct
2 Correct 1903 ms 1880 KB Output is correct
3 Correct 2147 ms 1936 KB Output is correct
4 Correct 2278 ms 2068 KB Output is correct
5 Correct 2265 ms 2052 KB Output is correct
6 Correct 1593 ms 1304 KB Output is correct
7 Execution timed out 2576 ms 2168 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Incorrect 0 ms 204 KB Output isn't correct
13 Halted 0 ms 0 KB -