Submission #891302

# Submission time Handle Problem Language Result Execution time Memory
891302 2023-12-22T17:09:10 Z lolicon Financial Report (JOI21_financial) C++14
48 / 100
4000 ms 12112 KB
#include <bits/stdc++.h>
using namespace std;

const int maxn = 3e5 + 5;

vector<int> V;
int A[maxn];
int n, D;

void getr(vector<int> &r) {
    set<int> st;
    vector<pair<int, int>> arr;
    vector<int> op(n + 1), ed(n + 1);
    for(int i = 1; i <= n; ++i) {
        arr.emplace_back(A[i], -i);
    }
    sort(begin(arr), end(arr));
    for(int i = 0; i < n; ++i) {
        int pos = -arr[i].second;
        op[pos] = ed[pos] = pos;
        auto it = st.upper_bound(pos);
        if(it != st.end() && op[*it] < pos) {
            r[pos] = *it + D;
            continue;
        }
        it = st.insert(pos).first;
        // printf("insert %d\n", pos);
        auto xx = next(it);
        r[pos] = pos + D;
        if(xx != st.end()) {
            if(*xx - pos <= D) {
                int ll = op[pos];
                int rr = ed[*xx];
                // printf("merge (%d, %d), (%d, %d)\n", op[pos], ed[pos], op[*xx], ed[*xx]);
                ed[ll] = rr;
                op[rr] = ll;
                r[pos] = rr + D;
                if(pos != ll) st.erase(pos);
                if(*xx != rr) st.erase(*xx);
            }
        }
        if(it != st.begin()) {
            xx = prev(it);
            if(pos - *xx <= D) {
                int ll = op[*xx];
                int rr = ed[pos];
                // printf("merge (%d, %d), (%d, %d)\n", op[pos], ed[pos], op[*xx], ed[*xx]);
                ed[ll] = rr;
                op[rr] = ll;
                
                if(pos != rr) st.erase(pos);
                if(*xx != ll) st.erase(*xx);
            }
        }
    }
}

void solve() {
    vector<int> dp(n + 1), r(n + 1);
    // for(int i = 1; i <= n; ++i) {
    //     int lst = i;
    //     for(int j = i; j <= n; ++j) {
    //         if(j - lst > D) break;
    //         if(A[j] <= A[i]) lst = j;
    //     }
    //     r[i] = lst + D;
    // }
    // for(int i = 1; i <= n; ++i) printf("%d%c", r[i], " \n"[i == n]);
    getr(r);
    // for(int i = 1; i <= n; ++i) printf("%d%c", r[i], " \n"[i == n]);
    // O(n^2) dp
    for(int i = 1; i <= n; ++i) {
        dp[i] = 1;
        for(int j = 1; j < i; ++j) {
            if(r[j] >= i && A[j] < A[i]) 
                dp[i] = max(dp[i], dp[j] + 1);
        }
    }
    cout << *max_element(begin(dp), end(dp)) << '\n';
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> D;
    for(int i = 1; i <= n; ++i) {
        cin >> A[i]; V.push_back(A[i]);
    }
    sort(begin(V), end(V));
    for(int i = 1; i <= n; ++i) {
        A[i] = lower_bound(begin(V), end(V), A[i]) - begin(V) + 1;
    }
    solve();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 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 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 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 0 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 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 600 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 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 0 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 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 600 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 23 ms 600 KB Output is correct
42 Correct 24 ms 600 KB Output is correct
43 Correct 39 ms 604 KB Output is correct
44 Correct 71 ms 604 KB Output is correct
45 Correct 63 ms 600 KB Output is correct
46 Correct 70 ms 600 KB Output is correct
47 Correct 26 ms 604 KB Output is correct
48 Correct 55 ms 604 KB Output is correct
49 Correct 61 ms 604 KB Output is correct
50 Correct 78 ms 692 KB Output is correct
51 Correct 18 ms 600 KB Output is correct
52 Correct 20 ms 600 KB Output is correct
53 Correct 17 ms 604 KB Output is correct
54 Correct 20 ms 708 KB Output is correct
55 Correct 66 ms 604 KB Output is correct
56 Correct 35 ms 856 KB Output is correct
57 Correct 45 ms 604 KB Output is correct
58 Correct 16 ms 604 KB Output is correct
59 Correct 17 ms 604 KB Output is correct
60 Correct 22 ms 712 KB Output is correct
61 Correct 22 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 4043 ms 11864 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4053 ms 12112 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 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 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 600 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 23 ms 600 KB Output is correct
42 Correct 24 ms 600 KB Output is correct
43 Correct 39 ms 604 KB Output is correct
44 Correct 71 ms 604 KB Output is correct
45 Correct 63 ms 600 KB Output is correct
46 Correct 70 ms 600 KB Output is correct
47 Correct 26 ms 604 KB Output is correct
48 Correct 55 ms 604 KB Output is correct
49 Correct 61 ms 604 KB Output is correct
50 Correct 78 ms 692 KB Output is correct
51 Correct 18 ms 600 KB Output is correct
52 Correct 20 ms 600 KB Output is correct
53 Correct 17 ms 604 KB Output is correct
54 Correct 20 ms 708 KB Output is correct
55 Correct 66 ms 604 KB Output is correct
56 Correct 35 ms 856 KB Output is correct
57 Correct 45 ms 604 KB Output is correct
58 Correct 16 ms 604 KB Output is correct
59 Correct 17 ms 604 KB Output is correct
60 Correct 22 ms 712 KB Output is correct
61 Correct 22 ms 600 KB Output is correct
62 Execution timed out 4043 ms 11864 KB Time limit exceeded
63 Halted 0 ms 0 KB -