답안 #636249

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
636249 2022-08-28T15:28:54 Z stoyan_malinin Peru (RMI20_peru) C++14
0 / 100
1 ms 340 KB
#include "peru.h"
#ifdef _LOCAL_
    #include "grader.cpp"
#endif // _LOCAL_

#include <vector>

using namespace std;

int convertToAns(const vector<long long> &dp)
{
    long long p23 = 1, ans = 0;
    const long long mod = 1e9 + 7;

    for(int i = dp.size()-1;i>=0;i--)
    {
        ans = (ans + dp[i]*p23)%mod;
        p23 = (p23*23)%mod;
    }

    return ans;
}

int solve(int n, int k, int* a)
{
    vector <long long> dp(n);

    dp[0] = a[0];
    for(int i = 1;i<n;i++)
    {
        dp[i] = 1e18;
        //cout << "###" << dp[i] << '\n';

        long long maxVal = -1;
        for(int j = i;j>=0 && i-j+1<=k;j--)
        {
            maxVal = max(maxVal, (long long)a[j]);
            //if(j!=0) cout << maxVal << " + " << dp[j-1] << '\n';
            //else cout << maxVal << " + " << "0" << '\n';

            if(j!=0) dp[i] = min(dp[i], dp[j-1] + maxVal);
            else dp[i] = min(dp[i], maxVal);

            //cout << "**" << dp[i] << '\n';
        }

        //cout << dp[i] << '\n';
    }

    return convertToAns(dp);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -