Submission #494518

#TimeUsernameProblemLanguageResultExecution timeMemory
494518leakedPeru (RMI20_peru)C++14
0 / 100
1 ms340 KiB
#include <bits/stdc++.h> #define f first #define s second #define m_p make_pair #define vec vector #define sz(x) (int)(x).size() #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() #define fast_rmi ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); using namespace std; typedef long long ll; const int N=4e5+1; const int M=1e9+7; ll dp[N]; ll pw[N]; int solve(int n,int k,int *a){ int ans=0; pw[0]=1; for(int i=1;i<n;i++) pw[i]=1ll*pw[i-1]*23%M; for(int i=1;i<=n;i++){ dp[i]=1e18; int mx=-1; for(int j=i-1;j>=0 && j>=i-k;j--){ mx=max(mx,a[j]); dp[i]=min(dp[i],dp[j]+mx); } // cout<<dp[i]<<' '; // ans*=23;ans%=M; // ans+=(dp[i]%M);ans%=M; ans+=1ll*(dp[i]%M)*pw[n-i]; ans%=M; } return ans; } //int a[100]; //signed main(){ // int n,k; // cin>>n>>k; // for(int i=0;i<n;i++) // cin>>a[i]; // cout<<solve(n,k,a); //}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...