# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
872621 | imarn | Peru (RMI20_peru) | C++14 | 1 ms | 348 KiB |
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>
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(x) x.begin(),x.end()
#define pb push_back
#define sz(x) (int)x.size()
#define f first
#define s second
#define vi vector<int>
#define vpii vector<pii>
#define ll long long
using namespace std;
const int inf=1e9+7;
int solve(int n, int k, int* v){
ll a[n+1];a[0]=0;
ll pw[n+1];pw[0]=1;
for(int i=1;i<=n;i++)pw[i]=(pw[i-1]*23)%inf;
for(int i=1;i<=n;i++)a[i]=*(v),v++;
deque<int>dq;dq.pb(0);ll dp[n+1];dp[0]=0;
for(int i=1;i<=n;i++){
while(!dq.empty()&&i-dq.front()>k)dq.pop_front();
while(!dq.empty()&&a[dq.back()]<=a[i])dq.pop_back();dq.pb(i);
dp[i] = dp[max(i-k,0)]+a[dq.front()];
for(int j=1;j<dq.size();j++){
dp[i] = min(dp[i],dp[dq[j-1]]+a[dq[j]]);
}
}ll ans=0;
for(int i=1;i<=n;i++){
ans+=(dp[i]*pw[n-i])%inf;
ans%=inf;
}
return (ans%inf+inf)%inf;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |