//Dost SEFEROĞLU
#pragma GCC optimize("O3,unroll-loops,Ofast")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define ff first
#define ss second
#define sp << " " <<
#define vi vector<int>
const int N = 5e2+1,inf = 2e18,MOD = 1e9+7;
void solve() {
int n,m;
cin >> n >> m;
vi a(n+1);
a[0] = 0;
for (int i=1;i<=n;i++) cin >> a[i];
int dp[n+1][2];
for (int i=1;i<=n;i++) for (int j=0;j<2;j++) dp[i][j] = -inf;
dp[1][1] = a[1] == m ? 1 : -inf;
dp[1][0] = 0;
for (int i=2;i<=n;i++) {
dp[i][0] = dp[i-1][0];
for (int j = i-1;j>=1;j--) {
if (abs(a[i]-a[j]) == m) dp[i][1] = max(dp[i][1],dp[j][1]+1);
dp[i][0] = max(dp[i][0],dp[j][1]);
dp[i][0] = max(dp[i][0],dp[j][0]);
}
}
cout << n-max(0ll,max(dp[n][1],dp[n][0])) << '\n';
}
signed main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#ifdef Dodi
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int t = 1;
//cin >> t;
while (t --> 0) solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |