#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int nmax = 2500000;
const int P = 1000000007;
ll dp[nmax];
int solve(int N, int K, int* S) {
for (int i = 1; i <= N; i++) dp[i] = LLONG_MAX;
for (int i = 1; i <= N; i++) {
int maxSoFar = -1;
for (int j = i - 1; j >= 0 && j >= i - K; j--) {
maxSoFar = max(maxSoFar, S[j]);
dp[i] = min(dp[i], (dp[j] + maxSoFar));
}
}
ll put23 = 1;
ll sum = 0;
for (int i = N; i >= 1; i--) {
sum = (sum + dp[i] * put23 % P) % P;
put23 = ( put23 * 23 ) % P;
}
return sum;
}
/*int s[nmax];
int main() {
int n,k;
in >> n >> k;
for (int i = 0; i < n; i++) in >> s[i];
out << solve(n , k , s);
}
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |