답안 #682134

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
682134 2023-01-15T21:49:00 Z sysia Let's Win the Election (JOI22_ho_t3) C++17
10 / 100
963 ms 4688 KB
//Sylwia Sapkowska
#include <bits/stdc++.h>
#pragma GCC optimize("O3", "unroll-loops")
using namespace std;

void __print(int x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef LOCAL
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define int long long
typedef pair<int, int> T;
typedef long double ld;
const int oo = 1e18, oo2 = 1e9+7, K = 30;
const int mod = 998244353;

void solve(){
    int n, k; cin >> n >> k;
    vector<T>tab;
    tab.emplace_back(-oo, -oo);
    for (int i = 1; i<=n; i++){
        int x, y; cin >> x >> y;
        if (y == -1) y = oo2;
        tab.emplace_back(x, y);
    }
    sort(tab.begin(), tab.end(),[](auto x, auto y){return x.second == y.second ? x.first < y.first : x.second < y.second;});
    ld ans = oo;
    for (int col = 1; col <= k+1; col++){
        vector dp(n+2, vector<ld>(k+2, oo));
        dp[0][0] = 0;
        for (int i = 1; i<col; i++){
            dp[i][i] = dp[i-1][i-1] + (ld)(tab[i].second)/(ld)(i);
        }
        for (int i = col; i<=n; i++){
            auto [a, b] = tab[i];
            for (int ck = 0; ck <= k; ck++){
                //dp[i][ck][col]-->
                //nic nie robimy --> dokladamy glos --> dokladamy glos i kolaboranta
                dp[i][ck] = min({dp[i-1][ck], 
                                    (ck ? dp[i-1][ck-1] + (ld)(a)/(ld)(col) : (ld)oo) 
                                    // (ck && col >= 2 && b != oo2 ? dp[ck-1][col-1] + (ld)(b)/(ld)(col-1) : (ld)oo)
                                });
                // debug(i, ck, dp[i][ck]);
            }
        }
        debug(col, dp[n][k]);
        ans = min(ans, dp[n][k]);
    }
    cout << fixed << setprecision(17) << ans << "\n";
}

int32_t main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    solve();

    return 0;
}
# 결과 실행 시간 메모리 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 1 ms 324 KB Output is correct
5 Correct 12 ms 924 KB Output is correct
6 Correct 72 ms 1584 KB Output is correct
7 Correct 246 ms 2512 KB Output is correct
8 Correct 610 ms 3724 KB Output is correct
9 Correct 917 ms 4616 KB Output is correct
10 Correct 497 ms 3408 KB Output is correct
# 결과 실행 시간 메모리 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 1 ms 324 KB Output is correct
5 Correct 12 ms 924 KB Output is correct
6 Correct 72 ms 1584 KB Output is correct
7 Correct 246 ms 2512 KB Output is correct
8 Correct 610 ms 3724 KB Output is correct
9 Correct 917 ms 4616 KB Output is correct
10 Correct 497 ms 3408 KB Output is correct
11 Correct 1 ms 328 KB Output is correct
12 Correct 104 ms 1800 KB Output is correct
13 Correct 137 ms 1692 KB Output is correct
14 Correct 102 ms 1548 KB Output is correct
15 Correct 501 ms 3384 KB Output is correct
16 Correct 473 ms 3376 KB Output is correct
17 Correct 513 ms 3316 KB Output is correct
18 Correct 924 ms 4560 KB Output is correct
19 Correct 934 ms 4688 KB Output is correct
20 Correct 963 ms 4644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 312 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 320 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 312 KB Output is correct
9 Incorrect 1 ms 212 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 312 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 320 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 312 KB Output is correct
9 Incorrect 1 ms 212 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 312 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 320 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 312 KB Output is correct
9 Incorrect 1 ms 212 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 943 ms 4584 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 1 ms 324 KB Output is correct
5 Correct 12 ms 924 KB Output is correct
6 Correct 72 ms 1584 KB Output is correct
7 Correct 246 ms 2512 KB Output is correct
8 Correct 610 ms 3724 KB Output is correct
9 Correct 917 ms 4616 KB Output is correct
10 Correct 497 ms 3408 KB Output is correct
11 Correct 1 ms 328 KB Output is correct
12 Correct 104 ms 1800 KB Output is correct
13 Correct 137 ms 1692 KB Output is correct
14 Correct 102 ms 1548 KB Output is correct
15 Correct 501 ms 3384 KB Output is correct
16 Correct 473 ms 3376 KB Output is correct
17 Correct 513 ms 3316 KB Output is correct
18 Correct 924 ms 4560 KB Output is correct
19 Correct 934 ms 4688 KB Output is correct
20 Correct 963 ms 4644 KB Output is correct
21 Correct 1 ms 312 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1 ms 320 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 312 KB Output is correct
29 Incorrect 1 ms 212 KB Output isn't correct
30 Halted 0 ms 0 KB -