이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |