#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]%mod)*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);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
324 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
324 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Execution timed out |
1055 ms |
9184 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1055 ms |
9184 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |