답안 #991909

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
991909 2024-06-03T11:27:38 Z crafticat Global Warming (CEOI18_glo) C++17
0 / 100
70 ms 5460 KB
#include <bits/stdc++.h>

using namespace std;
using pii = pair<int,int>;

vector<int> lis(vector<int> &arr, int constX) {
    vector<int> dp(arr.size());
    set<pii> s;
    for (int i = 0; i < arr.size();i++) {
        int v = arr[i];
        if (constX > 0) {
            auto it = s.lower_bound({v, 0});
            if (s.empty()) dp[i] = 0;
            else {
                it = s.lower_bound({v + constX, 0});
                if (it == s.end()) it--;
                dp[i] = it->second;
            }
        }

        if (s.empty()) {
            s.insert({v,1});
        }

        auto it = s.lower_bound({v,0});
        bool remOld = true;
        if (it == s.end()) {
            it--;
            remOld = false;
        }
        int p = it->second;
        if (it->first > v || !remOld) {
            if (remOld) s.erase(it);
            s.emplace(v,p + (!remOld));
        }


        if (constX == 0)
            dp[i] = p;
    }

    return dp;
}

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

    int n, x; cin >> n >> x;
    vector<int> arr(n), revArr(n);
    for (int i = 0; i < n; ++i) {
        cin >> arr[i];
        revArr[i] = -arr[i];
    }
    std::reverse(revArr.begin(), revArr.end());
    auto before = lis(arr,0), after = lis(revArr,x);
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        ans = max(ans, before[i] + after[n - 1 - i]);
    }
    cout << ans;

    return 0;
}

Compilation message

glo.cpp: In function 'std::vector<int> lis(std::vector<int>&, int)':
glo.cpp:9:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 |     for (int i = 0; i < arr.size();i++) {
      |                     ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 604 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 604 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 604 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 70 ms 5460 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 17 ms 1628 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 2892 KB Output is correct
2 Incorrect 37 ms 3016 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 604 KB Output isn't correct
3 Halted 0 ms 0 KB -