이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int temps[200005];
int pref_longest[200005];
int main() {
int n;
int x;
cin >> n >> x;
for (int i = 0; i < n; i++) {
cin >> temps[i];
}
vector<int> dp(n, INT_MAX);
int longest = 0;
// LIS ending at i;
for (int i = 0; i < n; i++) {
int j = lower_bound(dp.begin(), dp.end(), temps[i]) - dp.begin();
dp[j] = temps[i];
pref_longest[i] = j + 1;
longest = max(longest, pref_longest[i]);
}
dp = vector<int>(n, INT_MAX);
// LIS starting at i with incremented values from i to n;
for (int i = n - 1; i >= 0; i--) {
int pos = lower_bound(dp.begin(), dp.end(), -temps[i]+x)-dp.begin();
longest = max(longest, pref_longest[i] + pos);
int insert_pos = lower_bound(dp.begin(), dp.end(), -temps[i]) - dp.begin();
dp[insert_pos] = -temps[i];
}
cout << longest << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |