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<bits/stdc++.h>
#include<fstream>
using namespace std;
#define sz(a) (int)a.size()
#define ALL(v) v.begin(), v.end()
#define ALLR(v) v.rbegin(), v.rend()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
#define mpp make_pair
#include<iostream>
#include "peru.h"
using namespace std;
const int mxn = 4e5 + 5;
const ll mod = 1e9 + 7;
ll a[mxn + 1];
ll dp[mxn + 1], pw[mxn + 1];
int solve(int n, int k, int* v){
pw[0] = 1;
for(int i = 1; i < n; i++)pw[i] = (pw[i - 1] * 23) % mod;
for(int i = 1; i <= n; i++)a[i] = v[i - 1];
ll ans = 0;
for(int i = 1; i <= n; i++){
dp[i] = dp[i - 1] + a[i];
ll mx = a[i];
for(int j = i - 1; j >= max(i - k + 1, 1); j--){
mx = max(mx, a[j]);
dp[i] = min(dp[i], dp[j - 1] + mx);
}
ans = (ans + (dp[i] % mod) * pw[n - i]) % mod;
//cout << dp[i] << " ";
}
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... |