This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
typedef long long ll;
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
ll n, a, b, c;
std::string s;
std::cin >> n >> s >> a >> b >> c;
std::vector<ll> dp(n + 1);
dp[1] = a;
for (ll i = 2; i <= n; ++i) {
dp[i] = dp[i - 1] + a;
auto update_dp = [&](ll x, ll y) {
dp[i] = std::min(dp[i], dp[x] + b + y * c);
};
for (ll j = 2; j * j <= i; ++j) {
if (i % j == 0) {
update_dp(j, i / j);
update_dp(i / j, j);
}
}
}
std::cout << dp[n] << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |