Submission #1032770

# Submission time Handle Problem Language Result Execution time Memory
1032770 2024-07-24T08:18:46 Z vjudge1 Volontiranje (COCI21_volontiranje) C++17
50 / 110
1000 ms 8016 KB
#include <bits/stdc++.h>
using namespace std;

int main(){
    int n;
    cin >> n;

    int a[n];
    for (int i = 0; i < n; i ++)
        cin >> a[i];

    int lis = 0;
    int dp[n] = {}, par[n] = {};
    for (int i = n - 1; i >= 0; i --){
        dp[i] = 1;
        for (int j = i + 1; j < n; j ++)
            if (a[j] > a[i])
                dp[i] = max(dp[i], dp[j] + 1);
        lis = max(lis, dp[i]);
    }

    bool mark[n] = {};
    vector<vector<int>> output;
    for (int ii = 0; ii < n; ii ++){
        memset(dp, 0, sizeof dp);
        memset(par, 0, sizeof par);

        for (int i = n - 1; i >= 0; i --){
            if (mark[i]) continue;

            dp[i] = 1;
            par[i] = i;
            for (int j = i + 1; j < n; j ++){
                if (mark[j] or a[j] < a[i]) continue;
                if (dp[i] < dp[j] + 1 or (dp[i] == dp[j] + 1 and a[par[i]] < a[j])){
                    dp[i] = dp[j] + 1;
                    par[i] = j;
                }
            }
        }

        int mx = -1;
        for (int i = 0; i < n; i ++){
            if (dp[i] != lis) continue;
            if (mx == -1 or a[mx] < a[i])
                mx = i;
        }

        if (mx == -1) break;

        vector<int> cur;
        while (1){
            cur.push_back(mx);
            mark[mx] = 1;
            if (mx == par[mx]) break;
            mx = par[mx];
        }

        output.push_back(cur);
    }

    cout << output.size() << " " << lis << endl;
    for (auto vec : output){
        for (int x : vec)
            cout << x + 1 << " ";
        cout << endl;
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 432 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 436 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 432 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 436 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 3 ms 348 KB Output is correct
28 Correct 1 ms 436 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 116 ms 468 KB Output is correct
31 Correct 4 ms 348 KB Output is correct
32 Correct 8 ms 452 KB Output is correct
33 Correct 68 ms 348 KB Output is correct
34 Correct 62 ms 344 KB Output is correct
35 Correct 66 ms 440 KB Output is correct
36 Correct 2 ms 344 KB Output is correct
37 Correct 2 ms 348 KB Output is correct
38 Correct 4 ms 444 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 604 KB Output is correct
44 Correct 1 ms 344 KB Output is correct
45 Correct 1 ms 344 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 432 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 436 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 3 ms 348 KB Output is correct
28 Correct 1 ms 436 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 116 ms 468 KB Output is correct
31 Correct 4 ms 348 KB Output is correct
32 Correct 8 ms 452 KB Output is correct
33 Correct 68 ms 348 KB Output is correct
34 Correct 62 ms 344 KB Output is correct
35 Correct 66 ms 440 KB Output is correct
36 Correct 2 ms 344 KB Output is correct
37 Correct 2 ms 348 KB Output is correct
38 Correct 4 ms 444 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 604 KB Output is correct
44 Correct 1 ms 344 KB Output is correct
45 Correct 1 ms 344 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Execution timed out 1034 ms 8016 KB Time limit exceeded
48 Halted 0 ms 0 KB -