Submission #969019

#TimeUsernameProblemLanguageResultExecution timeMemory
969019dostsRabbit Carrot (LMIO19_triusis)C++17
0 / 100
0 ms348 KiB
//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(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...