이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define ioss ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back
int n, x;
int arr[200004], dp[200004];
signed main() {
ioss;
cin >> n >> x;
for(int i = 0; i < n; i++) cin >> arr[i];
if(x == 0) {
vector<int> tmp;
for(int i = 0; i < n; i++) {
if(i == 0) {
dp[i] = 1;
tmp.pb(arr[i]);
continue;
}
if(arr[i] > tmp.back()) dp[i] = dp[i-1]+1, tmp.pb(arr[i]);
else {
int cur = lower_bound(tmp.begin(), tmp.end(), arr[i])-tmp.begin();
tmp[cur] = arr[i];
dp[i] = dp[i-1];
// for(auto x : tmp) cout << x << " ";
// cout << endl;
}
// cout << " :: " << arr[i] << " " << tmp.back() << " " << dp[i] << endl;
}
cout << dp[n-1] << endl;
return 0;
}
vector<pii> range;
for(int j = 0; j < n; j++) {
for(int k = j; k < n; k++) {
range.pb({j, k});
}
}
int ans = 0;
for(auto [l, r] : range) {
// cout << l << " " << r << endl;
for(int k = -x; k <= x; k++) {
vector<int> tmp;
for(int i = 0; i < n; i++) dp[i] = 0;
for(int i = 0; i < n; i++) {
if(i == 0) {
dp[i] = 1;
tmp.pb(arr[i]);
continue;
}
if(i >= l && i <= r) arr[i] += k;
if(arr[i] > tmp.back()) dp[i] = dp[i-1]+1, tmp.pb(arr[i]);
else {
int cur = lower_bound(tmp.begin(), tmp.end(), arr[i])-tmp.begin();
tmp[cur] = arr[i];
dp[i] = dp[i-1];
// for(auto x : tmp) cout << x << " ";
// cout << endl;
}
// cout << " :: " << arr[i] << " " << tmp.back() << " " << dp[i] << endl;
if(i >= l && i <= r) arr[i] -= k;
ans = max(ans, dp[n-1]);
}
}
}
cout << ans << 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... |