Submission #854688

#TimeUsernameProblemLanguageResultExecution timeMemory
854688tibinytePeru (RMI20_peru)C++14
0 / 100
1 ms344 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int 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; }

Compilation message (stderr)

peru.cpp:7:17: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+16' to '2147483647' [-Woverflow]
    7 | const int inf = 1e16;
      |                 ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...