이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <fstream>
#define endl '\n'
#define mod 1000000007
#define INF 1000000000
#define INF2 1000000000000000000
///#define cin fin
///#define cout fout
using namespace std;
double const EPS = 1e-14;
typedef long long ll;
///ofstream fout("herding.out");
///ifstream fin("herding.in");
int main()
{
ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
int n; ll x; cin >> n >> x; ll arr[n+2] = {};
for(int i = 1; i <= n; i++) cin >> arr[i];
arr[n+1] = INF2;
ll dp1[n+2] = {}, dp2[n+2] = {};
for(int i = 1; i <= n; i++) {
for(int j = i-1; j >= 0; j--) {
if(arr[j] < arr[i]) {
dp1[i] = max(dp1[i],dp1[j]+1);
}
}
}
for(int i = n; i >= 1; i--) {
for(int j = i+1; j <= n+1; j++) {
if(arr[j] > arr[i]) {
// cout << i << ' ' << j << ' ' << dp2[i] << ' ' << dp2[j] << 'i' << endl;
dp2[i] = max(dp2[i],dp2[j]+1);
}
}
}
ll ans = 0;
/* for(int i = 1; i <= n; i++) {
cout << i << ' ' << dp2[i] << endl;
}
cout << "KKKK" << endl;
for(int i = 1; i <= n; i++) {
cout << i << ' ' << dp1[i] << endl;
}*/
for(int i = 1; i <= n; i++) {
for(int j = i-1; j >= 0; j--) {
if(arr[i]+x > arr[j]) {
ans = max(ans,dp2[i]+dp1[j]);
}
}
}
for(int i = n; i >= 1; i--) {
for(int j = i+1; j <= n+1; j++) {
if(arr[i]-x < arr[j]) {
ans = max(ans,dp1[i]+dp2[j]);
}
}
}
cout << ans << endl;
return 0;
}
# | 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... |