Submission #854688

# Submission time Handle Problem Language Result Execution time Memory
854688 2023-09-28T14:16:57 Z tibinyte Peru (RMI20_peru) C++14
0 / 100
1 ms 344 KB
#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

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 time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -