이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "algo/debug.h"
#endif
const int inf = 1e9;
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];
}
vector<int> prefix_dp(n + 1, inf), prefix_lis(n);
for (int i = 0; i < n; ++i) {
int j = (int) distance(prefix_dp.begin(),
upper_bound(
prefix_dp.begin(), prefix_dp.end(),
t[i]
)
) + 1;
prefix_dp[j] = t[i];
prefix_lis[i] = j;
}
vector<int> suffix_dp(n + 1, inf), suffix_lis(n);
for (int i = n - 1; i >= 0; --i) {
suffix_lis[i] = (int) distance(suffix_dp.begin(),
upper_bound(
suffix_dp.begin(), suffix_dp.end(),
-(t[i] - x)
)
) + 1;
int j = (int) distance(suffix_dp.begin(),
upper_bound(
suffix_dp.begin(), suffix_dp.end(),
-t[i]
)
) + 1;
suffix_dp[j] = t[i];
}
int ans = 0;
for (int i = 0; i < n; ++i) {
ans = max(ans, prefix_lis[i] + suffix_lis[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... |