Submission #682071

# Submission time Handle Problem Language Result Execution time Memory
682071 2023-01-15T15:08:59 Z kym Let's Win the Election (JOI22_ho_t3) C++14
32 / 100
1117 ms 4436 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define intd long double
#define debug(x) cout << '|' << x << '|' << '\n';
#define debug2(x, y) cout << x << " | " << y << '\n';
#define debug3(x, y, z) cout << x << " | " << y << " | " << z << '\n';

deque<pair<int, int>> v;
intd memo[510][510];
vector<int> precomp;
int N, K, intendedA;

intd dp(int idx, int sizeOfA) {
    if (memo[idx][sizeOfA] != 0) return memo[idx][sizeOfA];
    if (idx == N) return (sizeOfA == intendedA ? 0 : 1e18);
    intd res = 1e18;
    int sizeOfB = K - intendedA + 1;
    
    if (sizeOfA == intendedA && sizeOfB == 1) return 0;

    // take B
    if (idx < v.size() && v[idx].first != -1) {
        if (idx - sizeOfA + 1 >= sizeOfB) {
            res = min(res, dp(idx + 1, sizeOfA));
            // cout << idx << " " << sizeOfA << " " << "DON'T TAKE ANYTHING: " << dp(idx + 1, sizeOfA) << endl;
        }
        else {
            res = min(res, dp(idx + 1, sizeOfA) + (intd)v[idx].first / (intd)(idx - sizeOfA + 1));
            // cout << idx << " " << sizeOfA << " " << "TAKE B: " << dp(idx + 1, sizeOfA) + (intd)v[idx].first / (intd)(idx - sizeOfA + 1) << endl;
        }
    }
    // take A
    if (idx < v.size() && sizeOfA < intendedA) {
        res = min(res, dp(idx + 1, sizeOfA + 1) + (intd)v[idx].second / (intd)sizeOfB);
        // cout << idx << " " << sizeOfA << " " << "TAKE A: " << dp(idx + 1, sizeOfA + 1) + (intd)v[idx].second / (intd)sizeOfB << endl;
    }
    // take remainder of A
    if (sizeOfA < intendedA && intendedA - sizeOfA - 1 < precomp.size() && (idx - sizeOfA) >= sizeOfB - 1) {
        res = min(res, (intd)precomp[intendedA - sizeOfA - 1] / (intd)sizeOfB);
        // cout << idx << " " << sizeOfA << " TAKE REMAINDER OF A: " << (intd)precomp[intendedA - sizeOfA - 1] / (intd)sizeOfB << endl;
    }

    memo[idx][sizeOfA] = res;
    return res;
}

bool cmp(pair<int, int> a, pair<int, int> b) {
    if ((a.first == -1 && b.first == -1) || (a.first != -1 && b.first != -1)) {
        if (a.first != b.first) return a.first < b.first;
        return a.second < b.second;
    }
    if (b.first == -1) return true;
    return false;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> N >> K;
    for (int i = 0; i < N; i++) {
        int A, B;
        cin >> A >> B;
        v.push_back(make_pair(B, A));
    }
    sort(v.begin(), v.end(), cmp);
    // for (auto i : v) cout << i.first << " " << i.second << endl;
    for (int i = 0; i < N; i++) {
        if (v[i].first == -1) {
            if (precomp.empty()) precomp.push_back(v[i].second);
            else precomp.push_back(precomp.back() + v[i].second);
        }
    }
    for (int i = N - 1; i >= 0; i--) {
        if (v[i].first == -1) v.pop_back();
    }
    // for (auto i : precomp) cout << i << endl;
    cout << fixed << setprecision(15);

    intd res = 1e18;
    for (int i = 0; i <= K; i++) {
        intendedA = i;
        memset(memo, 0, sizeof memo);
        // cout << intendedA << endl;
        res = min(res, dp(0, 0));
    }
    cout << res;
}

Compilation message

Main.cpp: In function 'long double dp(long long int, long long int)':
Main.cpp:23:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::deque<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     if (idx < v.size() && v[idx].first != -1) {
      |         ~~~~^~~~~~~~~~
Main.cpp:34:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::deque<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |     if (idx < v.size() && sizeOfA < intendedA) {
      |         ~~~~^~~~~~~~~~
Main.cpp:39:56: 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]
   39 |     if (sizeOfA < intendedA && intendedA - sizeOfA - 1 < precomp.size() && (idx - sizeOfA) >= sizeOfB - 1) {
      |                                ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4280 KB Output is correct
2 Correct 3 ms 4308 KB Output is correct
3 Correct 3 ms 4308 KB Output is correct
4 Correct 3 ms 4308 KB Output is correct
5 Correct 7 ms 4308 KB Output is correct
6 Correct 16 ms 4408 KB Output is correct
7 Correct 42 ms 4404 KB Output is correct
8 Correct 54 ms 4308 KB Output is correct
9 Correct 58 ms 4388 KB Output is correct
10 Correct 35 ms 4308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4280 KB Output is correct
2 Correct 3 ms 4308 KB Output is correct
3 Correct 3 ms 4308 KB Output is correct
4 Correct 3 ms 4308 KB Output is correct
5 Correct 7 ms 4308 KB Output is correct
6 Correct 16 ms 4408 KB Output is correct
7 Correct 42 ms 4404 KB Output is correct
8 Correct 54 ms 4308 KB Output is correct
9 Correct 58 ms 4388 KB Output is correct
10 Correct 35 ms 4308 KB Output is correct
11 Correct 2 ms 4308 KB Output is correct
12 Correct 321 ms 4436 KB Output is correct
13 Correct 83 ms 4308 KB Output is correct
14 Correct 32 ms 4388 KB Output is correct
15 Correct 685 ms 4436 KB Output is correct
16 Correct 297 ms 4404 KB Output is correct
17 Correct 72 ms 4396 KB Output is correct
18 Correct 1086 ms 4436 KB Output is correct
19 Correct 533 ms 4404 KB Output is correct
20 Correct 139 ms 4392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4352 KB Output is correct
2 Correct 2 ms 4308 KB Output is correct
3 Correct 2 ms 4308 KB Output is correct
4 Correct 3 ms 4308 KB Output is correct
5 Correct 4 ms 4308 KB Output is correct
6 Correct 4 ms 4308 KB Output is correct
7 Correct 3 ms 4308 KB Output is correct
8 Correct 3 ms 4308 KB Output is correct
9 Correct 3 ms 4388 KB Output is correct
10 Correct 3 ms 4388 KB Output is correct
11 Correct 3 ms 4308 KB Output is correct
12 Correct 3 ms 4308 KB Output is correct
13 Correct 4 ms 4308 KB Output is correct
14 Correct 3 ms 4308 KB Output is correct
15 Correct 3 ms 4308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4352 KB Output is correct
2 Correct 2 ms 4308 KB Output is correct
3 Correct 2 ms 4308 KB Output is correct
4 Correct 3 ms 4308 KB Output is correct
5 Correct 4 ms 4308 KB Output is correct
6 Correct 4 ms 4308 KB Output is correct
7 Correct 3 ms 4308 KB Output is correct
8 Correct 3 ms 4308 KB Output is correct
9 Correct 3 ms 4388 KB Output is correct
10 Correct 3 ms 4388 KB Output is correct
11 Correct 3 ms 4308 KB Output is correct
12 Correct 3 ms 4308 KB Output is correct
13 Correct 4 ms 4308 KB Output is correct
14 Correct 3 ms 4308 KB Output is correct
15 Correct 3 ms 4308 KB Output is correct
16 Correct 4 ms 4308 KB Output is correct
17 Correct 3 ms 4308 KB Output is correct
18 Incorrect 4 ms 4372 KB Output isn't correct
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4352 KB Output is correct
2 Correct 2 ms 4308 KB Output is correct
3 Correct 2 ms 4308 KB Output is correct
4 Correct 3 ms 4308 KB Output is correct
5 Correct 4 ms 4308 KB Output is correct
6 Correct 4 ms 4308 KB Output is correct
7 Correct 3 ms 4308 KB Output is correct
8 Correct 3 ms 4308 KB Output is correct
9 Correct 3 ms 4388 KB Output is correct
10 Correct 3 ms 4388 KB Output is correct
11 Correct 3 ms 4308 KB Output is correct
12 Correct 3 ms 4308 KB Output is correct
13 Correct 4 ms 4308 KB Output is correct
14 Correct 3 ms 4308 KB Output is correct
15 Correct 3 ms 4308 KB Output is correct
16 Correct 4 ms 4308 KB Output is correct
17 Correct 3 ms 4308 KB Output is correct
18 Incorrect 4 ms 4372 KB Output isn't correct
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1083 ms 4436 KB Output is correct
2 Correct 1051 ms 4436 KB Output is correct
3 Correct 1101 ms 4436 KB Output is correct
4 Correct 1100 ms 4436 KB Output is correct
5 Correct 1066 ms 4420 KB Output is correct
6 Correct 1117 ms 4436 KB Output is correct
7 Correct 1088 ms 4436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4280 KB Output is correct
2 Correct 3 ms 4308 KB Output is correct
3 Correct 3 ms 4308 KB Output is correct
4 Correct 3 ms 4308 KB Output is correct
5 Correct 7 ms 4308 KB Output is correct
6 Correct 16 ms 4408 KB Output is correct
7 Correct 42 ms 4404 KB Output is correct
8 Correct 54 ms 4308 KB Output is correct
9 Correct 58 ms 4388 KB Output is correct
10 Correct 35 ms 4308 KB Output is correct
11 Correct 2 ms 4308 KB Output is correct
12 Correct 321 ms 4436 KB Output is correct
13 Correct 83 ms 4308 KB Output is correct
14 Correct 32 ms 4388 KB Output is correct
15 Correct 685 ms 4436 KB Output is correct
16 Correct 297 ms 4404 KB Output is correct
17 Correct 72 ms 4396 KB Output is correct
18 Correct 1086 ms 4436 KB Output is correct
19 Correct 533 ms 4404 KB Output is correct
20 Correct 139 ms 4392 KB Output is correct
21 Correct 2 ms 4352 KB Output is correct
22 Correct 2 ms 4308 KB Output is correct
23 Correct 2 ms 4308 KB Output is correct
24 Correct 3 ms 4308 KB Output is correct
25 Correct 4 ms 4308 KB Output is correct
26 Correct 4 ms 4308 KB Output is correct
27 Correct 3 ms 4308 KB Output is correct
28 Correct 3 ms 4308 KB Output is correct
29 Correct 3 ms 4388 KB Output is correct
30 Correct 3 ms 4388 KB Output is correct
31 Correct 3 ms 4308 KB Output is correct
32 Correct 3 ms 4308 KB Output is correct
33 Correct 4 ms 4308 KB Output is correct
34 Correct 3 ms 4308 KB Output is correct
35 Correct 3 ms 4308 KB Output is correct
36 Correct 4 ms 4308 KB Output is correct
37 Correct 3 ms 4308 KB Output is correct
38 Incorrect 4 ms 4372 KB Output isn't correct
39 Halted 0 ms 0 KB -