Submission #871022

#TimeUsernameProblemLanguageResultExecution timeMemory
871022Trisanu_DasGiraffes (JOI22_giraffes)C++17
59 / 100
58 ms109396 KiB
#include<bits/stdc++.h> using namespace std; int n, a[400]; int dp[400][400][400]; int main(){ cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = n; i; i--){ for (int j = 1; j <= n; j++) dp[i][i][j] = (a[j] != i); for (int j = i+1; j <= n; j++) for (int k = 1; k+j-i <= n; k++) dp[i][j][k] = min({dp[i+1][j][k] + (a[k+j-i] != i), dp[i+1][j][k+1] + (a[k] != i) , dp[i][j-1][k] + (a[k+j-i] != j), dp[i][j-1][k+1] + (a[k] != j)}); } cout << dp[1][n][1] << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...