Submission #854690

#TimeUsernameProblemLanguageResultExecution timeMemory
854690tibinytePeru (RMI20_peru)C++14
18 / 100
625 ms11368 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll inf = 1e16; const int mod = 1e9 + 7; struct Mint { int val; Mint(int x = 0) { val = x % mod; } Mint(long long x) { val = x % mod; } Mint operator+(Mint oth) { return val + oth.val; } Mint operator-(Mint oth) { return val - oth.val + mod; } Mint operator*(Mint oth) { return 1ll * val * oth.val; } }; Mint powmod(int a, int b) { if (b == 0) { return 1; } if (b % 2 == 1) { return powmod(a, b - 1) * a; } Mint P = powmod(a, b / 2); return P * P; } int solve(int n, int k, int *S) { vector<int> a(n + 1); for (int i = 1; i <= n; ++i) { a[i] = S[i - 1]; } Mint ans = 0; vector<ll> dp(n + 1, inf); dp[0] = 0; for (int i = 1; i <= n; ++i) { int maxi = 0; for (int j = i; j >= max(1, i - k + 1); --j) { maxi = max(maxi, a[j]); dp[i] = min(dp[i], dp[j - 1] + maxi); } ans = ans + powmod(23, n - i) * dp[i]; } return ans.val; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...