Submission #508402

# Submission time Handle Problem Language Result Execution time Memory
508402 2022-01-13T10:22:51 Z KoD Volontiranje (COCI21_volontiranje) C++17
110 / 110
400 ms 151124 KB
#include <bits/stdc++.h>

using std::vector;
using std::array;
using std::pair;
using std::tuple;

constexpr int INF = std::numeric_limits<int>::max() / 2;

template <class F> struct RecLambda : private F {
    explicit RecLambda(F&& f) : F(std::forward<F>(f)) {}
    template <class... Args> decltype(auto) operator()(Args&&... args) const {
        return F::operator()(*this, std::forward<Args>(args)...);
    }
};

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int N;
    std::cin >> N;
    vector<int> P(N);
    for (auto& x : P) {
        std::cin >> x;
        x -= 1;
    }
    vector<int> left(N);
    {
        vector<int> dp(N + 1, INF);
        dp[0] = -INF;
        for (int i = 0; i < N; ++i) {
            auto itr = std::lower_bound(dp.begin(), dp.end(), P[i]);
            left[i] = itr - dp.begin();
            *itr = P[i];
        }
    }
    vector<int> right(N);
    {
        vector<int> dp(N + 1, INF);
        dp[0] = -INF;
        for (int i = N - 1; i >= 0; --i) {
            auto itr = std::lower_bound(dp.begin(), dp.end(), -P[i]);
            right[i] = itr - dp.begin();
            *itr = -P[i];
        }
    }
    int max = 0;
    for (int i = 0; i < N; ++i) {
        max = std::max(max, left[i] + right[i] - 1);
    }
    vector<vector<int>> list(max);
    for (int i = 0; i < N; ++i) {
        if (left[i] + right[i] - 1 == max) {
            list[left[i] - 1].push_back(i);
        }
    }
    vector<vector<int>> ans;
    vector<int> idx(max);
    vector<char> used(N);
    while (idx[0] < (int)list[0].size()) {
        vector<int> path;
        RecLambda([&](auto&& dfs, const int k, const int i) -> bool {
            const int u = list[k][i];
            path.push_back(u);
            if (k + 1 == max) {
                ans.push_back(path);
                return true;
            }
            while (idx[k + 1] < (int)list[k + 1].size()) {
                const int v = list[k + 1][idx[k + 1]];
                if (u > v or used[v]) {
                    idx[k + 1] += 1;
                    continue;
                }
                if (P[u] > P[v]) {
                    break;
                }
                if (dfs(k + 1, idx[k + 1])) {
                    return true;
                }
                idx[k + 1] += 1;
            }
            path.pop_back();
            return false;
        })(0, idx[0]++);
        for (const int u : path) {
            used[u] = true;
        }
    }
    std::cout << ans.size() << ' ' << max << '\n';
    for (const auto& v : ans) {
        for (int i = 0; i < max; ++i) {
            std::cout << v[i] + 1 << " \n"[i + 1 == max];
        }
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 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 0 ms 312 KB Output is correct
8 Correct 0 ms 312 KB Output is correct
9 Correct 0 ms 308 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 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 1 ms 204 KB Output is correct
17 Correct 1 ms 204 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 332 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 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 0 ms 312 KB Output is correct
8 Correct 0 ms 312 KB Output is correct
9 Correct 0 ms 308 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 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 1 ms 204 KB Output is correct
17 Correct 1 ms 204 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 332 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 0 ms 204 KB Output is correct
24 Correct 1 ms 292 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 332 KB Output is correct
28 Correct 0 ms 204 KB Output is correct
29 Correct 1 ms 444 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 312 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 1 ms 204 KB Output is correct
41 Correct 0 ms 312 KB Output is correct
42 Correct 0 ms 204 KB Output is correct
43 Correct 0 ms 308 KB Output is correct
44 Correct 0 ms 204 KB Output is correct
45 Correct 0 ms 204 KB Output is correct
46 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 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 0 ms 312 KB Output is correct
8 Correct 0 ms 312 KB Output is correct
9 Correct 0 ms 308 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 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 1 ms 204 KB Output is correct
17 Correct 1 ms 204 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 332 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 0 ms 204 KB Output is correct
24 Correct 1 ms 292 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 332 KB Output is correct
28 Correct 0 ms 204 KB Output is correct
29 Correct 1 ms 444 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 312 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 1 ms 204 KB Output is correct
41 Correct 0 ms 312 KB Output is correct
42 Correct 0 ms 204 KB Output is correct
43 Correct 0 ms 308 KB Output is correct
44 Correct 0 ms 204 KB Output is correct
45 Correct 0 ms 204 KB Output is correct
46 Correct 0 ms 204 KB Output is correct
47 Correct 103 ms 9364 KB Output is correct
48 Correct 99 ms 9600 KB Output is correct
49 Correct 120 ms 12096 KB Output is correct
50 Correct 211 ms 21400 KB Output is correct
51 Correct 47 ms 5080 KB Output is correct
52 Correct 400 ms 151124 KB Output is correct
53 Correct 287 ms 84048 KB Output is correct
54 Correct 261 ms 33724 KB Output is correct
55 Correct 231 ms 33872 KB Output is correct
56 Correct 2 ms 492 KB Output is correct
57 Correct 164 ms 16628 KB Output is correct
58 Correct 38 ms 4280 KB Output is correct
59 Correct 33 ms 3524 KB Output is correct
60 Correct 168 ms 17172 KB Output is correct
61 Correct 113 ms 11488 KB Output is correct
62 Correct 1 ms 312 KB Output is correct
63 Correct 0 ms 312 KB Output is correct
64 Correct 0 ms 204 KB Output is correct
65 Correct 0 ms 204 KB Output is correct
66 Correct 1 ms 204 KB Output is correct
67 Correct 0 ms 204 KB Output is correct
68 Correct 1 ms 204 KB Output is correct
69 Correct 0 ms 312 KB Output is correct