Submission #588242

# Submission time Handle Problem Language Result Execution time Memory
588242 2022-07-02T21:15:10 Z stevancv Global Warming (CEOI18_glo) C++14
47 / 100
70 ms 5284 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 - 1; 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 1 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 Incorrect 0 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 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 Incorrect 0 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 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 Incorrect 0 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 61 ms 5224 KB Output is correct
2 Correct 69 ms 5172 KB Output is correct
3 Correct 70 ms 5236 KB Output is correct
4 Correct 60 ms 5160 KB Output is correct
5 Correct 45 ms 5284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 1488 KB Output is correct
2 Correct 14 ms 1480 KB Output is correct
3 Correct 14 ms 1564 KB Output is correct
4 Correct 13 ms 1512 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 12 ms 1488 KB Output is correct
7 Correct 13 ms 1488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 2772 KB Output is correct
2 Correct 29 ms 2704 KB Output is correct
3 Correct 63 ms 5152 KB Output is correct
4 Correct 45 ms 5252 KB Output is correct
5 Correct 23 ms 2768 KB Output is correct
6 Correct 37 ms 4948 KB Output is correct
7 Correct 47 ms 4996 KB Output is correct
8 Correct 22 ms 2756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 Incorrect 0 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -