Submission #858805

#TimeUsernameProblemLanguageResultExecution timeMemory
858805iulia_morariuPeru (RMI20_peru)C++14
0 / 100
1 ms344 KiB
#include <bits/stdc++.h> #include <peru.h> using namespace std; #define Mod 1000000007 int solve ( int n, int k, int* v ){ long long int dp[n + 1]; dp[0] = 0; for(int i = 1; i <= n; i++){ long long int maxi = v[i - 1]; dp[i] = LLONG_MAX; //cout << "i = " << i << " maxi = " << maxi << endl; for(int j = i - 1; j >= 0 && i - j <= k; j--){ dp[i] = min( dp[i], dp[j] + maxi ); //cout << " -- > j = " << j << " dp[j] = " << dp[j] << " maxi = " << maxi << endl; maxi = max( (long long)v[j - 1], maxi ); } dp[i] %= Mod; } /* cout << "dp : "; for(int i = 1; i <= n; i++) cout << dp[i] << " "; cout << endl; */ long long int sum = 0; long long int p = 1; for(int i = n; i > 0; i--){ sum += (p * dp[i]) % Mod; p *= 23; p %= Mod; } return sum; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...