Submission #1045152

# Submission time Handle Problem Language Result Execution time Memory
1045152 2024-08-05T17:39:36 Z IdanRosen Global Warming (CEOI18_glo) C++
100 / 100
43 ms 8644 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef long double ld;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    ll n, x;
    cin >> n >> x;

    vector<ll> arr(n);
    for (auto &i: arr) cin >> i;

    vector<ll> lis(n);
    {
        vector<ll> dp(n, -1);
        ll len = 0;

        for (ll i = 0; i < n; i++) {
            ll val = arr[i];

            ll start = 0;
            ll end = len;
            while (start < end) {
                ll mid = start + (end - start) / 2;

                if (arr[dp[mid]] < val) start = mid + 1;
                else end = mid;
            }

            lis[i] = start + 1;

            dp[start] = i;
            if (start == len) ++len;
        }
    }

    vector<ll> lis_rev(n);
    {
        vector<ll> dp(n);
        ll len = 0;

        for (ll i = n - 1; i > 0; i--) {
            ll val = arr[i];

            ll start = 0;
            ll end = len;

            while (start < end) {
                ll mid = start + (end - start) / 2;

                if (arr[dp[mid]] > val - x) start = mid + 1;
                else end = mid;
            }

            lis_rev[i] = start + 1;

            start = 0;
            end = len;

            while (start < end) {
                ll mid = start + (end - start) / 2;

                if (arr[dp[mid]] > val) start = mid + 1;
                else end = mid;
            }

            dp[start] = i;
            if (start == len) ++len;
        }
    }

    ll best_lis = 0;
    for (ll i = 0; i < n; i++) best_lis = max(best_lis, lis[i] + lis_rev[i] - 1);

    cout << best_lis;
}
# Verdict Execution time Memory Grader output
1 Correct 1 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 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 1 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 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 0 ms 448 KB Output is correct
13 Correct 1 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 1 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 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 0 ms 448 KB Output is correct
13 Correct 1 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 0 ms 348 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 36 ms 8508 KB Output is correct
2 Correct 43 ms 8644 KB Output is correct
3 Correct 41 ms 8500 KB Output is correct
4 Correct 36 ms 8504 KB Output is correct
5 Correct 21 ms 7732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 2512 KB Output is correct
2 Correct 8 ms 2372 KB Output is correct
3 Correct 9 ms 2260 KB Output is correct
4 Correct 5 ms 2128 KB Output is correct
5 Correct 0 ms 360 KB Output is correct
6 Correct 5 ms 2296 KB Output is correct
7 Correct 7 ms 2516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 4428 KB Output is correct
2 Correct 16 ms 4420 KB Output is correct
3 Correct 33 ms 8600 KB Output is correct
4 Correct 21 ms 7748 KB Output is correct
5 Correct 10 ms 4168 KB Output is correct
6 Correct 19 ms 7560 KB Output is correct
7 Correct 21 ms 8124 KB Output is correct
8 Correct 14 ms 4424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 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 0 ms 448 KB Output is correct
13 Correct 1 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 0 ms 348 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 36 ms 8508 KB Output is correct
28 Correct 43 ms 8644 KB Output is correct
29 Correct 41 ms 8500 KB Output is correct
30 Correct 36 ms 8504 KB Output is correct
31 Correct 21 ms 7732 KB Output is correct
32 Correct 9 ms 2512 KB Output is correct
33 Correct 8 ms 2372 KB Output is correct
34 Correct 9 ms 2260 KB Output is correct
35 Correct 5 ms 2128 KB Output is correct
36 Correct 0 ms 360 KB Output is correct
37 Correct 5 ms 2296 KB Output is correct
38 Correct 7 ms 2516 KB Output is correct
39 Correct 16 ms 4428 KB Output is correct
40 Correct 16 ms 4420 KB Output is correct
41 Correct 33 ms 8600 KB Output is correct
42 Correct 21 ms 7748 KB Output is correct
43 Correct 10 ms 4168 KB Output is correct
44 Correct 19 ms 7560 KB Output is correct
45 Correct 21 ms 8124 KB Output is correct
46 Correct 14 ms 4424 KB Output is correct
47 Correct 21 ms 4428 KB Output is correct
48 Correct 18 ms 4540 KB Output is correct
49 Correct 36 ms 8508 KB Output is correct
50 Correct 21 ms 7744 KB Output is correct
51 Correct 19 ms 5828 KB Output is correct
52 Correct 24 ms 7744 KB Output is correct
53 Correct 18 ms 7740 KB Output is correct
54 Correct 25 ms 8512 KB Output is correct
55 Correct 30 ms 8500 KB Output is correct