Submission #588244

# Submission time Handle Problem Language Result Execution time Memory
588244 2022-07-02T21:17:39 Z stevancv Global Warming (CEOI18_glo) C++14
100 / 100
72 ms 7204 KB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    auto MakeLIS = [&] (vector<int> v, int f) {
        vector<int> pom(n + 1, 1e9);
        vector<int> ret;
        if (f) for (int i = 0; i < n; i++) v[i] = -v[i];
        for (int i = 0; i < n; i++) {
            int l = 1, r = n;
            int ans = 0;
            while (l <= r) {
                int mid = l + r >> 1;
                if (pom[mid] < v[i]) {
                    l = mid + 1;
                    ans = mid;
                }
                else r = mid - 1;
            }
            ans += 1;
            ret.push_back(ans);
            smin(pom[ans], v[i]);
        }
        return ret;
    };
    vector<int> x = MakeLIS(a, 0);
    reverse(a.begin(), a.end());
    vector<int> y = MakeLIS(a, 1);
    reverse(a.begin(), a.end());
    reverse(y.begin(), y.end());
    int ans = 1;
    vector<int> pom(n + 1, 2e9);
    for (int i = 0; i < n; i++) {
        int l = 1, r = n;
        int w = 0;
        while (l <= r) {
            int mid = l + r >> 1;
            if (pom[mid] - k < a[i]) {
                l = mid + 1;
                w = mid;
            }
            else r = mid - 1;
        }
        smin(pom[x[i]], a[i]);
        smax(ans, w + y[i]);
    }
    cout << ans << en;
    return 0;
}

Compilation message

glo.cpp: In lambda function:
glo.cpp:25:29: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   25 |                 int mid = l + r >> 1;
      |                           ~~^~~
glo.cpp: In function 'int main()':
glo.cpp:49:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   49 |             int mid = l + r >> 1;
      |                       ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 316 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 316 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 316 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 316 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 316 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 324 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 320 KB Output is correct
24 Correct 1 ms 324 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 72 ms 5240 KB Output is correct
2 Correct 61 ms 5272 KB Output is correct
3 Correct 62 ms 5168 KB Output is correct
4 Correct 64 ms 5156 KB Output is correct
5 Correct 45 ms 5172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 1488 KB Output is correct
2 Correct 17 ms 1560 KB Output is correct
3 Correct 16 ms 1544 KB Output is correct
4 Correct 11 ms 1544 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 11 ms 1548 KB Output is correct
7 Correct 12 ms 1488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 2752 KB Output is correct
2 Correct 27 ms 2756 KB Output is correct
3 Correct 53 ms 5160 KB Output is correct
4 Correct 47 ms 5164 KB Output is correct
5 Correct 25 ms 2784 KB Output is correct
6 Correct 44 ms 4956 KB Output is correct
7 Correct 44 ms 5024 KB Output is correct
8 Correct 21 ms 2756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 316 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 316 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 324 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 320 KB Output is correct
24 Correct 1 ms 324 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 72 ms 5240 KB Output is correct
28 Correct 61 ms 5272 KB Output is correct
29 Correct 62 ms 5168 KB Output is correct
30 Correct 64 ms 5156 KB Output is correct
31 Correct 45 ms 5172 KB Output is correct
32 Correct 16 ms 1488 KB Output is correct
33 Correct 17 ms 1560 KB Output is correct
34 Correct 16 ms 1544 KB Output is correct
35 Correct 11 ms 1544 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 11 ms 1548 KB Output is correct
38 Correct 12 ms 1488 KB Output is correct
39 Correct 26 ms 2752 KB Output is correct
40 Correct 27 ms 2756 KB Output is correct
41 Correct 53 ms 5160 KB Output is correct
42 Correct 47 ms 5164 KB Output is correct
43 Correct 25 ms 2784 KB Output is correct
44 Correct 44 ms 4956 KB Output is correct
45 Correct 44 ms 5024 KB Output is correct
46 Correct 21 ms 2756 KB Output is correct
47 Correct 32 ms 3632 KB Output is correct
48 Correct 32 ms 3764 KB Output is correct
49 Correct 66 ms 7064 KB Output is correct
50 Correct 48 ms 6296 KB Output is correct
51 Correct 43 ms 5096 KB Output is correct
52 Correct 53 ms 6528 KB Output is correct
53 Correct 43 ms 6416 KB Output is correct
54 Correct 47 ms 7204 KB Output is correct
55 Correct 57 ms 7200 KB Output is correct