Submission #1000520

# Submission time Handle Problem Language Result Execution time Memory
1000520 2024-06-17T16:22:18 Z niwrad Global Warming (CEOI18_glo) C++17
100 / 100
109 ms 6260 KB
#include <bits/stdc++.h>

using namespace std;
int inf = 2e9 + 7;


int main() {
    int n, x;
    cin >> n >> x;
    vector<int> vec(n);
    for (int i = 0; i < n; i++) {
        cin >> vec[i];
    }
    vector<int> suff_dp(n + 1, -inf);
    suff_dp[0] = inf;
    vector<pair<int, int>> steps(n, {-1, -1});
    for (int i = n - 1; i >= 0; i--) {
        int l = (int) (upper_bound(suff_dp.begin(), suff_dp.end(), vec[i] + x, greater_equal<int>()) - suff_dp.begin());
        if (suff_dp[l] < vec[i] + x) {
            steps[i] = {l, suff_dp[l]};
            suff_dp[l] = vec[i] + x;
        }
    }
    int max = 0;
    for (int i = 0; i <= n; i++) {
        if (suff_dp[i] != -inf) {
            max = i;
        }
    }
    vector<int> pref_dp(n + 1, inf);
    pref_dp[0] = -inf;
    for (int i = 0; i < n; i++) {
        int s = -1;
        if (steps[i].first != -1) {
            s = steps[i].first;
            suff_dp[steps[i].first] = steps[i].second;
        }
        int l = (int) (upper_bound(pref_dp.begin(), pref_dp.end(), vec[i]) - pref_dp.begin());
        if (pref_dp[l - 1] < vec[i] && vec[i] < pref_dp[l]) {
            pref_dp[l] = vec[i];
            int p = (int) (lower_bound(suff_dp.begin(), suff_dp.end(), vec[i], greater<int>()) - suff_dp.begin());
            l += p - 1;
            max = std::max(max, l);
        }
        if (s != -1) {
            int p = (int) (lower_bound(pref_dp.begin(), pref_dp.end(), suff_dp[s]) - pref_dp.begin());
            max = std::max(max, s + p - 1);
        }
    }
    cout << max << "\n";
}


# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 440 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 348 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 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 440 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 348 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 348 KB Output is correct
12 Correct 1 ms 360 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 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 440 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 348 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 348 KB Output is correct
12 Correct 1 ms 360 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 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 448 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 604 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 91 ms 6180 KB Output is correct
2 Correct 80 ms 6228 KB Output is correct
3 Correct 109 ms 6228 KB Output is correct
4 Correct 100 ms 6228 KB Output is correct
5 Correct 57 ms 5472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 1884 KB Output is correct
2 Correct 20 ms 1908 KB Output is correct
3 Correct 20 ms 1880 KB Output is correct
4 Correct 12 ms 1628 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 15 ms 1624 KB Output is correct
7 Correct 17 ms 1884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 3252 KB Output is correct
2 Correct 64 ms 3156 KB Output is correct
3 Correct 80 ms 6248 KB Output is correct
4 Correct 60 ms 5456 KB Output is correct
5 Correct 28 ms 2896 KB Output is correct
6 Correct 51 ms 5424 KB Output is correct
7 Correct 60 ms 5968 KB Output is correct
8 Correct 32 ms 3164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 440 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 348 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 348 KB Output is correct
12 Correct 1 ms 360 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 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 448 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 604 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 91 ms 6180 KB Output is correct
28 Correct 80 ms 6228 KB Output is correct
29 Correct 109 ms 6228 KB Output is correct
30 Correct 100 ms 6228 KB Output is correct
31 Correct 57 ms 5472 KB Output is correct
32 Correct 19 ms 1884 KB Output is correct
33 Correct 20 ms 1908 KB Output is correct
34 Correct 20 ms 1880 KB Output is correct
35 Correct 12 ms 1628 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 15 ms 1624 KB Output is correct
38 Correct 17 ms 1884 KB Output is correct
39 Correct 34 ms 3252 KB Output is correct
40 Correct 64 ms 3156 KB Output is correct
41 Correct 80 ms 6248 KB Output is correct
42 Correct 60 ms 5456 KB Output is correct
43 Correct 28 ms 2896 KB Output is correct
44 Correct 51 ms 5424 KB Output is correct
45 Correct 60 ms 5968 KB Output is correct
46 Correct 32 ms 3164 KB Output is correct
47 Correct 44 ms 3156 KB Output is correct
48 Correct 40 ms 3152 KB Output is correct
49 Correct 80 ms 6260 KB Output is correct
50 Correct 55 ms 5444 KB Output is correct
51 Correct 37 ms 4176 KB Output is correct
52 Correct 58 ms 5456 KB Output is correct
53 Correct 48 ms 5460 KB Output is correct
54 Correct 63 ms 6228 KB Output is correct
55 Correct 73 ms 6224 KB Output is correct