이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "algo/debug.h"
#endif
const int inf = 1e9;
vector<int> lis(vector<int> const& a, bool value = false) {
int n = (int) a.size();
vector<int> ret(n);
vector<int> d(n + 1, inf);
d[0] = -inf;
for (int i = 0; i < n; ++i) {
int j = (int) distance(d.begin(),
upper_bound(d.begin(), d.end(), a[i])
);
if (d[j - 1] < a[i] && a[i] < d[j]) {
ret[i] = j;
d[j] = a[i];
}
}
if (value) {
for (int i = 0; i <= n; ++i) {
if (d[i] < inf) {
ret[0] = i;
}
}
}
return ret;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, x;
cin >> n >> x;
vector<int> t(n);
for (int i = 0; i < n; ++i) {
cin >> t[i];
}
int ans = lis(t, true).front();
for (int i = 0; i < n; ++i) {
t[i] -= x;
}
vector<int> L = lis(t);
for (int i = 0; i < n; ++i) {
t[i] += x;
}
reverse(t.begin(), t.end());
vector<int> R = lis(t);
reverse(R.begin(), R.end());
for (int i = 0; i < n; ++i) {
ans = max(ans, L[i] + R[i] - 1);
}
cout << ans << '\n';
}
/* stuff you should look for
* int overflow, array bounds
* special cases (n=1?)
* do smth instead of nothing and stay organized
* WRITE STUFF DOWN
* DON'T GET STUCK ON ONE APPROACH
*/
# | 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... |