Submission #636249

#TimeUsernameProblemLanguageResultExecution timeMemory
636249stoyan_malininPeru (RMI20_peru)C++14
0 / 100
1 ms340 KiB
#include "peru.h" #ifdef _LOCAL_ #include "grader.cpp" #endif // _LOCAL_ #include <vector> using namespace std; int convertToAns(const vector<long long> &dp) { long long p23 = 1, ans = 0; const long long mod = 1e9 + 7; for(int i = dp.size()-1;i>=0;i--) { ans = (ans + dp[i]*p23)%mod; p23 = (p23*23)%mod; } return ans; } int solve(int n, int k, int* a) { vector <long long> dp(n); dp[0] = a[0]; for(int i = 1;i<n;i++) { dp[i] = 1e18; //cout << "###" << dp[i] << '\n'; long long maxVal = -1; for(int j = i;j>=0 && i-j+1<=k;j--) { maxVal = max(maxVal, (long long)a[j]); //if(j!=0) cout << maxVal << " + " << dp[j-1] << '\n'; //else cout << maxVal << " + " << "0" << '\n'; if(j!=0) dp[i] = min(dp[i], dp[j-1] + maxVal); else dp[i] = min(dp[i], maxVal); //cout << "**" << dp[i] << '\n'; } //cout << dp[i] << '\n'; } return convertToAns(dp); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...