Submission #1115671

# Submission time Handle Problem Language Result Execution time Memory
1115671 2024-11-20T18:40:24 Z proshel_afgan_2015 Akcija (COCI21_akcija) C++14
110 / 110
1203 ms 32080 KB
#include <bits/stdc++.h>
# define int long long
//# define double long double
# define all(x) (x).begin(), (x).end()
# define rall(x) (x).rbegin(), (x).rend()
# define pi pair<int, int>
# define f first
# define s second

using namespace std;

const int c = 1e13;
vector<vector<int>> dp;
vector<pi> p;
int n, k;
int rs = 0;
vector<int> rss;

pi get(int cc) {
    pi pr;
    pr.f = (cc + c - 1) / c;
    pr.s = pr.f * c - cc;
    return pr;
}

void fnd(int i, int cc, int x, bool b) {
    if (i == n) {
//        cout << get(cc).f << " " << get(cc).s << " " << cc << " " << x << " " << b << "\n";
        if (b) {
            rss.push_back(cc);
        }
        ++rs;
        return;
    }
    auto [j, t] = get(cc);
    int mb = dp[i + 1][j];
    if (cc + mb > x) {
        fnd(i + 1, cc, x, b);
    }
    if (rs >= k) return;
    if (j + 1 <= p[i].s) {
        mb = dp[i + 1][j + 1] + c - p[i].f;
        if (cc + mb > x) {
            fnd(i + 1, cc + c - p[i].f, x, b);
        }
    }
}

bool ok(int x) {
    rs = 0;
    fnd(0, 0, x, false);
//    cout << rs << " " << get(x).f << " " << get(x).s << "\n";
    return rs < k;
}

void solve() {
    cin >> n >> k;
    p.assign(n, {});
    for (int i = 0; i < n; ++i) {
        cin >> p[i].f >> p[i].s;
    }
    sort(all(p), [](pi a, pi b) {return a.s < b.s;});
    dp.assign(n + 1, vector<int>(n + 1));
    for (int i = n - 1; i >= 0; --i) {
        for (int j = 0; j <= n; ++j) {
            int d = p[i].s;
            dp[i][j] = dp[i + 1][j];
            if (j + 1 <= d) {
                dp[i][j] = max(dp[i][j], dp[i + 1][j + 1] + c - p[i].f);
            }
        }
    }
    int l = 0, r = 1e18;
    while (r - l > 1) {
        int m = (l + r) / 2;
        if (ok(m)) {
            r = m;
        } else {
            l = m;
        }
    }
    rs = 0;
    fnd(0, 0, l, true);
    sort(all(rss));
    reverse(all(rss));
    while (rss.size() < k) {
        rss.push_back(l);
    }
    for (int i = 0; i < k; ++i) {
        cout << get(rss[i]).f << " " << get(rss[i]).s << "\n";
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
//    cin >> t;
    while (t--) {
        solve();
    }
}

Compilation message

Main.cpp: In function 'void fnd(long long int, long long int, long long int, bool)':
Main.cpp:35:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   35 |     auto [j, t] = get(cc);
      |          ^
Main.cpp: In function 'void solve()':
Main.cpp:86:23: 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]
   86 |     while (rss.size() < k) {
      |            ~~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 23 ms 29512 KB Output is correct
2 Correct 25 ms 32008 KB Output is correct
3 Correct 27 ms 27228 KB Output is correct
4 Correct 20 ms 26464 KB Output is correct
5 Correct 25 ms 31272 KB Output is correct
6 Correct 20 ms 26192 KB Output is correct
7 Correct 24 ms 31568 KB Output is correct
8 Correct 20 ms 27216 KB Output is correct
9 Correct 20 ms 25944 KB Output is correct
10 Correct 21 ms 27984 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 29512 KB Output is correct
2 Correct 25 ms 32008 KB Output is correct
3 Correct 27 ms 27228 KB Output is correct
4 Correct 20 ms 26464 KB Output is correct
5 Correct 25 ms 31272 KB Output is correct
6 Correct 20 ms 26192 KB Output is correct
7 Correct 24 ms 31568 KB Output is correct
8 Correct 20 ms 27216 KB Output is correct
9 Correct 20 ms 25944 KB Output is correct
10 Correct 21 ms 27984 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 24 ms 29520 KB Output is correct
15 Correct 25 ms 32080 KB Output is correct
16 Correct 21 ms 27268 KB Output is correct
17 Correct 21 ms 26448 KB Output is correct
18 Correct 25 ms 31352 KB Output is correct
19 Correct 20 ms 26192 KB Output is correct
20 Correct 24 ms 31724 KB Output is correct
21 Correct 25 ms 27208 KB Output is correct
22 Correct 23 ms 25936 KB Output is correct
23 Correct 23 ms 27984 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 29456 KB Output is correct
2 Correct 29 ms 32012 KB Output is correct
3 Correct 25 ms 26960 KB Output is correct
4 Correct 23 ms 26448 KB Output is correct
5 Correct 27 ms 31312 KB Output is correct
6 Correct 23 ms 26208 KB Output is correct
7 Correct 32 ms 31568 KB Output is correct
8 Correct 22 ms 27216 KB Output is correct
9 Correct 23 ms 25936 KB Output is correct
10 Correct 25 ms 27976 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 336 KB Output is correct
2 Correct 4 ms 336 KB Output is correct
3 Correct 3 ms 504 KB Output is correct
4 Correct 3 ms 516 KB Output is correct
5 Correct 3 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 3 ms 336 KB Output is correct
8 Correct 3 ms 336 KB Output is correct
9 Correct 3 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 3 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 336 KB Output is correct
2 Correct 3 ms 460 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 336 KB Output is correct
5 Correct 3 ms 504 KB Output is correct
6 Correct 2 ms 336 KB Output is correct
7 Correct 2 ms 336 KB Output is correct
8 Correct 2 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 29512 KB Output is correct
2 Correct 25 ms 32008 KB Output is correct
3 Correct 27 ms 27228 KB Output is correct
4 Correct 20 ms 26464 KB Output is correct
5 Correct 25 ms 31272 KB Output is correct
6 Correct 20 ms 26192 KB Output is correct
7 Correct 24 ms 31568 KB Output is correct
8 Correct 20 ms 27216 KB Output is correct
9 Correct 20 ms 25944 KB Output is correct
10 Correct 21 ms 27984 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 24 ms 29520 KB Output is correct
15 Correct 25 ms 32080 KB Output is correct
16 Correct 21 ms 27268 KB Output is correct
17 Correct 21 ms 26448 KB Output is correct
18 Correct 25 ms 31352 KB Output is correct
19 Correct 20 ms 26192 KB Output is correct
20 Correct 24 ms 31724 KB Output is correct
21 Correct 25 ms 27208 KB Output is correct
22 Correct 23 ms 25936 KB Output is correct
23 Correct 23 ms 27984 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 27 ms 29456 KB Output is correct
28 Correct 29 ms 32012 KB Output is correct
29 Correct 25 ms 26960 KB Output is correct
30 Correct 23 ms 26448 KB Output is correct
31 Correct 27 ms 31312 KB Output is correct
32 Correct 23 ms 26208 KB Output is correct
33 Correct 32 ms 31568 KB Output is correct
34 Correct 22 ms 27216 KB Output is correct
35 Correct 23 ms 25936 KB Output is correct
36 Correct 25 ms 27976 KB Output is correct
37 Correct 1 ms 336 KB Output is correct
38 Correct 1 ms 336 KB Output is correct
39 Correct 1 ms 336 KB Output is correct
40 Correct 3 ms 336 KB Output is correct
41 Correct 4 ms 336 KB Output is correct
42 Correct 3 ms 504 KB Output is correct
43 Correct 3 ms 516 KB Output is correct
44 Correct 3 ms 336 KB Output is correct
45 Correct 1 ms 336 KB Output is correct
46 Correct 3 ms 336 KB Output is correct
47 Correct 3 ms 336 KB Output is correct
48 Correct 3 ms 336 KB Output is correct
49 Correct 1 ms 336 KB Output is correct
50 Correct 1 ms 336 KB Output is correct
51 Correct 1 ms 336 KB Output is correct
52 Correct 3 ms 336 KB Output is correct
53 Correct 2 ms 336 KB Output is correct
54 Correct 3 ms 460 KB Output is correct
55 Correct 2 ms 504 KB Output is correct
56 Correct 2 ms 336 KB Output is correct
57 Correct 3 ms 504 KB Output is correct
58 Correct 2 ms 336 KB Output is correct
59 Correct 2 ms 336 KB Output is correct
60 Correct 2 ms 336 KB Output is correct
61 Correct 1 ms 336 KB Output is correct
62 Correct 1 ms 336 KB Output is correct
63 Correct 1 ms 336 KB Output is correct
64 Correct 1 ms 336 KB Output is correct
65 Correct 1 ms 336 KB Output is correct
66 Correct 489 ms 29596 KB Output is correct
67 Correct 563 ms 32072 KB Output is correct
68 Correct 604 ms 27176 KB Output is correct
69 Correct 462 ms 26448 KB Output is correct
70 Correct 1203 ms 31560 KB Output is correct
71 Correct 473 ms 26428 KB Output is correct
72 Correct 148 ms 31768 KB Output is correct
73 Correct 111 ms 27408 KB Output is correct
74 Correct 218 ms 26108 KB Output is correct
75 Correct 561 ms 28176 KB Output is correct
76 Correct 1 ms 336 KB Output is correct
77 Correct 1 ms 336 KB Output is correct
78 Correct 9 ms 336 KB Output is correct