답안 #529452

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
529452 2022-02-23T03:12:56 Z wiwiho Let's Win the Election (JOI22_ho_t3) C++14
61 / 100
2500 ms 3288 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 long 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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 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 216 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 3 ms 332 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 2 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 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 216 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 3 ms 332 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 583 ms 636 KB Output is correct
13 Correct 818 ms 692 KB Output is correct
14 Correct 136 ms 432 KB Output is correct
15 Execution timed out 2594 ms 2304 KB Time limit exceeded
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 0 ms 204 KB Output is correct
5 Correct 1 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 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 276 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 0 ms 204 KB Output is correct
5 Correct 1 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 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 276 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 272 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 0 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 1 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 0 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 0 ms 204 KB Output is correct
36 Correct 1 ms 204 KB Output is correct
37 Correct 1 ms 204 KB Output is correct
38 Correct 0 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 0 ms 204 KB Output is correct
5 Correct 1 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 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 276 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 272 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 0 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 1 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 0 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 0 ms 204 KB Output is correct
36 Correct 1 ms 204 KB Output is correct
37 Correct 1 ms 204 KB Output is correct
38 Correct 0 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 1 ms 204 KB Output is correct
41 Correct 1 ms 204 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 4 ms 324 KB Output is correct
44 Correct 5 ms 332 KB Output is correct
45 Correct 15 ms 460 KB Output is correct
46 Correct 11 ms 348 KB Output is correct
47 Correct 15 ms 332 KB Output is correct
48 Correct 20 ms 332 KB Output is correct
49 Correct 32 ms 380 KB Output is correct
50 Correct 18 ms 364 KB Output is correct
51 Correct 26 ms 392 KB Output is correct
52 Correct 29 ms 332 KB Output is correct
53 Correct 12 ms 332 KB Output is correct
54 Correct 20 ms 332 KB Output is correct
55 Correct 24 ms 364 KB Output is correct
56 Correct 15 ms 332 KB Output is correct
57 Correct 20 ms 360 KB Output is correct
58 Correct 21 ms 368 KB Output is correct
59 Correct 21 ms 332 KB Output is correct
60 Correct 21 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2577 ms 3288 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 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 216 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 3 ms 332 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 583 ms 636 KB Output is correct
13 Correct 818 ms 692 KB Output is correct
14 Correct 136 ms 432 KB Output is correct
15 Execution timed out 2594 ms 2304 KB Time limit exceeded
16 Halted 0 ms 0 KB -