답안 #640185

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
640185 2022-09-13T21:59:49 Z danikoynov Peru (RMI20_peru) C++14
0 / 100
1 ms 340 KB
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 2.5e6 + 10;
const ll inf = 1e18, mod = 1e9 + 7;

ll a[maxn], dp[maxn], to[maxn];


int solve(int n, int k, int *S)
{
    for (int i = 0; i < n; i ++)
        a[i + 1] = S[i];


    stack < int > sc;
    for (int i = 1; i <= n; i ++)
    {
        while(!sc.empty() && a[sc.top()] < a[i])
        {
            to[sc.top()] = i;
            sc.pop();
        }

        sc.push(i);
    }

    deque < int > dq;
    multiset < int > mt;
    for (int i = 1; i <= n; i ++)
    {
        while(!dq.empty() && a[dq.back()] <= a[i])
        {
            ll sum = a[dq.back()];
            dq.pop_back();
            if (!dq.empty())
            {
                sum = sum + dp[dq.back()];
                mt.erase(mt.find(sum));
            }
        }
        if (!dq.empty())
        {
            ll sum = dp[dq.back()] + a[i];
            mt.insert(sum);
        }
        dq.push_back(i);
        while(!dq.empty() && dq.front() <= i - k)
        {
            ll sum = dp[dq.front()];
        dq.pop_front();
        if (!dq.empty())
        {
            sum = sum + a[dq.front()];
            mt.erase(mt.find(sum));
        }
        }
        dp[i] = inf;
        if (!mt.empty())
            dp[i] = *mt.begin();
        dp[i] = min(dp[i], dp[max(0, i - k)] + a[dq.front()]);


    }
    /**for (int i = 1; i <= n; i ++)
        cout << dp[i] << " ";
    cout << endl;*/
    ll cur = 1, ans = 0;
    for (int i = n; i > 0; i --)
    {
        ans = (ans + (dp[i] % mod) * cur) % mod;
        cur = (cur * (ll)23) % mod;
    }
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -