Submission #858853

#TimeUsernameProblemLanguageResultExecution timeMemory
858853alexdumitruPeru (RMI20_peru)C++14
0 / 100
1 ms348 KiB
#include <bits/stdc++.h> using namespace std; long long getAns(long long dp[], long long n) { long long mul = 1; long long ans = 0; const long long MOD = 1e9 + 7; for(long long i = n - 1; i >= 0; i--) { ans = (1LL * ans + dp[i] * mul) % MOD; mul = (1LL * mul * 23) % MOD; } return ans; } int solve(int n, int k, int *s) { long long dp[n]; long long Max = 0; for(long long i = 0; i < k; i++) { if(s[i] > Max) Max = s[i]; dp[i] = Max; } for(long long i = k; i < n; i++) { long long currMax = s[i]; dp[i] = LLONG_MAX; for(long long j = i - 1; j >= i - k; j--) { if(dp[i] > dp[j] + currMax) dp[i] = dp[j] + currMax; if(s[j] > currMax) currMax = s[j]; } } return getAns(dp, n); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...