답안 #640187

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
640187 2022-09-13T22:00:57 Z danikoynov Peru (RMI20_peru) C++14
100 / 100
468 ms 98072 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 < ll > 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 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 63 ms 11528 KB Output is correct
16 Correct 62 ms 11768 KB Output is correct
17 Correct 65 ms 11748 KB Output is correct
18 Correct 47 ms 11756 KB Output is correct
19 Correct 56 ms 11760 KB Output is correct
20 Correct 46 ms 11696 KB Output is correct
21 Correct 66 ms 11760 KB Output is correct
22 Correct 66 ms 11812 KB Output is correct
23 Correct 68 ms 11904 KB Output is correct
24 Correct 64 ms 11776 KB Output is correct
25 Correct 64 ms 11812 KB Output is correct
26 Correct 63 ms 11796 KB Output is correct
27 Correct 65 ms 11836 KB Output is correct
28 Correct 62 ms 11788 KB Output is correct
29 Correct 62 ms 12064 KB Output is correct
30 Correct 65 ms 11820 KB Output is correct
31 Correct 65 ms 11792 KB Output is correct
32 Correct 64 ms 11940 KB Output is correct
33 Correct 74 ms 11756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 11528 KB Output is correct
2 Correct 62 ms 11768 KB Output is correct
3 Correct 65 ms 11748 KB Output is correct
4 Correct 47 ms 11756 KB Output is correct
5 Correct 56 ms 11760 KB Output is correct
6 Correct 46 ms 11696 KB Output is correct
7 Correct 66 ms 11760 KB Output is correct
8 Correct 66 ms 11812 KB Output is correct
9 Correct 68 ms 11904 KB Output is correct
10 Correct 64 ms 11776 KB Output is correct
11 Correct 64 ms 11812 KB Output is correct
12 Correct 63 ms 11796 KB Output is correct
13 Correct 65 ms 11836 KB Output is correct
14 Correct 62 ms 11788 KB Output is correct
15 Correct 62 ms 12064 KB Output is correct
16 Correct 65 ms 11820 KB Output is correct
17 Correct 65 ms 11792 KB Output is correct
18 Correct 64 ms 11940 KB Output is correct
19 Correct 74 ms 11756 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 328 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 403 ms 69332 KB Output is correct
35 Correct 426 ms 92752 KB Output is correct
36 Correct 417 ms 92680 KB Output is correct
37 Correct 440 ms 92716 KB Output is correct
38 Correct 468 ms 92784 KB Output is correct
39 Correct 426 ms 93016 KB Output is correct
40 Correct 434 ms 92940 KB Output is correct
41 Correct 425 ms 92948 KB Output is correct
42 Correct 444 ms 92928 KB Output is correct
43 Correct 156 ms 37508 KB Output is correct
44 Correct 191 ms 56952 KB Output is correct
45 Correct 186 ms 56924 KB Output is correct
46 Correct 177 ms 56888 KB Output is correct
47 Correct 437 ms 94968 KB Output is correct
48 Correct 439 ms 94980 KB Output is correct
49 Correct 439 ms 95432 KB Output is correct
50 Correct 411 ms 96568 KB Output is correct
51 Correct 464 ms 96100 KB Output is correct
52 Correct 439 ms 98072 KB Output is correct
53 Correct 443 ms 96908 KB Output is correct
54 Correct 460 ms 92640 KB Output is correct
55 Correct 411 ms 92560 KB Output is correct
56 Correct 394 ms 92628 KB Output is correct
57 Correct 413 ms 92744 KB Output is correct
58 Correct 418 ms 92760 KB Output is correct
59 Correct 425 ms 92892 KB Output is correct
60 Correct 426 ms 92588 KB Output is correct
61 Correct 460 ms 95464 KB Output is correct
62 Correct 455 ms 94948 KB Output is correct
63 Correct 443 ms 94788 KB Output is correct