Submission #802193

#TimeUsernameProblemLanguageResultExecution timeMemory
802193NothingXDGiraffes (JOI22_giraffes)C++17
59 / 100
53 ms56148 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef double ld; void debug_out(){cerr<<endl;} template<typename Head, typename... Tail> void debug_out(Head H, Tail... T){ cerr << H << ' '; debug_out(T...); } #define debug(...) cerr << "(" << #__VA_ARGS__ << "): ", debug_out(__VA_ARGS__) #define F first #define S second #define all(x) x.begin(), x.end() #define MP(x, y) make_pair(x, y) const int maxn = 300 + 10; int n, a[maxn]; int dp[maxn][maxn][maxn]; 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...