Submission #1072917

#TimeUsernameProblemLanguageResultExecution timeMemory
1072917kunzaZa183Tortoise (CEOI21_tortoise)C++17
0 / 100
88 ms211752 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 300; int dp[maxn][maxn][maxn][2]; int main() { int n; cin>>n; vector<int> vi(n); for(auto &a:vi) cin>>a; for(int i = 0; i< maxn;i++) for(int j = 0; j < maxn; j++) for(int k = 0; k < maxn;k++) for(int l = 0; l < 2; l++) dp[i][j][k][l] = -1; auto repmax = [&](int &cur,int x) { cur = max(cur, x); }; //tim, pos, last, has if(vi[0] >= 1) { dp[0][0][1][1] = 1; }else dp[0][0][0][0] = 0; for(int i = 0; i < 3*n ;i++) for(int j = 0; j < n; j++) for(int k = 0;k <= n; k++) { // cout<<i<<' '<<j<<' '<<k<<' '<<dp[i][j][k][0]<<' '<<dp[i][j][k][1]<<'\n'; if(dp[i][j][k][0]!=-1 ){ //send forward if(j + 1 < n) { repmax(dp[i + 1][j+1][k][0], dp[i][j][k][0]); if(vi[j+1] >= 1 && k <= j + 1 && i + 1 <= 2*(j+1)) { repmax(dp[i+1][j+1][j + 2][1], dp[i][j][k][0] + 1); } } //send back if(j - 1>= 0) { repmax(dp[i + 1][j-1][k][0], dp[i][j][k][0]); if(vi[j-1] >= 1 && k <= j - 1 && i + 1 <= 2*(j-1)) { repmax(dp[i+1][j - 1][j][1], dp[i][j][k][0] + 1); } } } if(dp[i][j][k][1] != -1) { if(j + 1 < n) { if(vi[j+1] == -1) { repmax(dp[i+1][j + 1][k][0], dp[i][j][k][1]); }else repmax(dp[i+ 1][j + 1][k][1], dp[i][j][k][1]); } if(j - 1 < n) { if(vi[j - 1] == -1) { repmax(dp[i + 1][j - 1][k][0], dp[i][j][k][1]); }else repmax(dp[i+1][j-1][k][1], dp[i + 1][j - 1][k][1]); } } } int maxval = 0; for(int i = 0; i <= 2*n; i++) for(int j = 0; j < n; j++) for(int k = 0; k < n; k++) maxval = max({maxval, dp[i][j][k][0], dp[i][j][k][1]}); cout<<count(vi.begin(), vi.end(), 1) - maxval<<'\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...
#Verdict Execution timeMemoryGrader output
Fetching results...