This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "peru.h"
#include <bits/stdc++.h>
#define ll long long
#define oo 1e17
using namespace std;
const int MAX = 2002, MOD = 1e9 + 7;
int arr[MAX];
ll dp[MAX];
int solve(int n, int k, int* v){
for(int i = 1; i <= n; i++){
dp[i] = oo;
}
for(int i = 0; i < n; i++){
arr[i + 1] = v[i];
}
for(int i = 1; i <= n; i++){
int m = 0;
for(int j = 1; j <= k; j++){
if(i - j < 0) break;
m = max(arr[i - j + 1], m);
dp[i] = min(dp[i - j] + m, dp[i]);
}
}
ll ans = 0;
ll p = 1;
for(int i = n; i >= 1; i--){
ans += dp[i] % MOD * p % MOD;
ans %= MOD;
p *= 23;
p %= MOD;
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |