Submission #876866

#TimeUsernameProblemLanguageResultExecution timeMemory
876866TAhmed33Peru (RMI20_peru)C++14
0 / 100
30 ms29520 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 = s[i - 1]; dp[i] = 1e18; for (int j = i - 1; j >= i - k; j++) { dp[i] = min(dp[i], dp[j] + mx); mx = max(mx, s[i - 1]); } ret = add(ret, mul(pw[n - i], dp[i])); } return ret; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...