Submission #876873

#TimeUsernameProblemLanguageResultExecution timeMemory
876873TAhmed33Peru (RMI20_peru)C++17
0 / 100
29 ms29528 KiB
#include <bits/stdc++.h> #include <peru.h> using namespace std; typedef long long ll; const int MAXN = 2500000; const int MOD = 1e9 + 7; int add (int a, int b) { a += b; if (a >= MOD) a -= MOD; return a; } int sub (int a, int b) { a -= b; if (a < 0) a += MOD; return a; } int mul (int a, int b) { return (a * 1ll * b) % MOD; } int pw[MAXN + 25]; ll dp[MAXN + 25]; int solve (int n, int k, int *s) { pw[0] = 1; for (int i = 1; i < MAXN + 25; i++) { pw[i] = mul(i, pw[i - 1]); } int ret = 0; for (int i = 1; i <= n; i++) { int mx = 0; dp[i] = 1e18; for (int j = i - 1; j >= max(0, i - k); j++) { mx = max(mx, s[j]); dp[i] = min(dp[i], dp[j] + mx); } ret = add(ret, mul(pw[n - i], dp[i] % MOD)); } return ret; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...