Submission #849401

# Submission time Handle Problem Language Result Execution time Memory
849401 2023-09-14T14:54:43 Z TahirAliyev Peru (RMI20_peru) C++17
100 / 100
261 ms 73556 KB
#include "peru.h"
#include <bits/stdc++.h>

#define ll long long
#define oo 1e17
#define pii pair<int, int>

using namespace std;

const int MAX = 25e5 + 5, MOD = 1e9 + 7;
ll arr[MAX];
ll dp[MAX];
ll val[MAX];
priority_queue<pair<ll, int>> s;
bool d[MAX];
deque<int> dq;

void clearQ(){
    while(d[s.top().second]){
        s.pop();
    }
}

int solve(int n, int k, int* v){
    for(int i = 0; i < n; i++){
        arr[i + 1] = v[i];
    }
    dq.push_back(1);
    dp[1] = arr[1];
    for(int i = 2; i <= n; i++){
        while(dq.size() && arr[dq.back()] <= arr[i]){
            if(dq.size() > 1) d[dq.back()] = 1;
            dq.pop_back();
        }
        if(dq.size() && dq.front() == i - k){
            dq.pop_front();
            if(dq.size()){
                d[dq.front()] = 1;
            }
        }
        dp[i] = oo;
        if(dq.size()){
            val[i] = dp[dq.back()] + arr[i];
            s.push({-val[i], i});
            clearQ();
            dp[i] = -s.top().first;
        }
        dq.push_back(i);
        dp[i] = min(dp[i], arr[dq.front()] + dp[max(0, i - k)]);
    }
    ll ans = 0;
    for(int i = 1; i <= n; i++){
        ans *= 23;
        ans += dp[i];
        ans %= MOD;
    }
    return ans;
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 2 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8536 KB Output is correct
11 Correct 1 ms 8540 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 2 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8536 KB Output is correct
11 Correct 1 ms 8540 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 37 ms 21076 KB Output is correct
16 Correct 38 ms 21044 KB Output is correct
17 Correct 37 ms 21264 KB Output is correct
18 Correct 38 ms 21244 KB Output is correct
19 Correct 38 ms 19284 KB Output is correct
20 Correct 39 ms 19352 KB Output is correct
21 Correct 39 ms 21272 KB Output is correct
22 Correct 41 ms 21328 KB Output is correct
23 Correct 41 ms 21332 KB Output is correct
24 Correct 40 ms 21084 KB Output is correct
25 Correct 40 ms 19292 KB Output is correct
26 Correct 36 ms 19280 KB Output is correct
27 Correct 37 ms 21328 KB Output is correct
28 Correct 38 ms 21332 KB Output is correct
29 Correct 37 ms 19540 KB Output is correct
30 Correct 38 ms 21072 KB Output is correct
31 Correct 37 ms 21076 KB Output is correct
32 Correct 43 ms 21328 KB Output is correct
33 Correct 36 ms 21072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 21076 KB Output is correct
2 Correct 38 ms 21044 KB Output is correct
3 Correct 37 ms 21264 KB Output is correct
4 Correct 38 ms 21244 KB Output is correct
5 Correct 38 ms 19284 KB Output is correct
6 Correct 39 ms 19352 KB Output is correct
7 Correct 39 ms 21272 KB Output is correct
8 Correct 41 ms 21328 KB Output is correct
9 Correct 41 ms 21332 KB Output is correct
10 Correct 40 ms 21084 KB Output is correct
11 Correct 40 ms 19292 KB Output is correct
12 Correct 36 ms 19280 KB Output is correct
13 Correct 37 ms 21328 KB Output is correct
14 Correct 38 ms 21332 KB Output is correct
15 Correct 37 ms 19540 KB Output is correct
16 Correct 38 ms 21072 KB Output is correct
17 Correct 37 ms 21076 KB Output is correct
18 Correct 43 ms 21328 KB Output is correct
19 Correct 36 ms 21072 KB Output is correct
20 Correct 1 ms 8540 KB Output is correct
21 Correct 1 ms 8540 KB Output is correct
22 Correct 1 ms 8540 KB Output is correct
23 Correct 1 ms 8540 KB Output is correct
24 Correct 2 ms 8540 KB Output is correct
25 Correct 1 ms 8540 KB Output is correct
26 Correct 1 ms 8540 KB Output is correct
27 Correct 1 ms 8540 KB Output is correct
28 Correct 1 ms 8540 KB Output is correct
29 Correct 1 ms 8536 KB Output is correct
30 Correct 1 ms 8540 KB Output is correct
31 Correct 1 ms 8540 KB Output is correct
32 Correct 1 ms 8540 KB Output is correct
33 Correct 1 ms 8540 KB Output is correct
34 Correct 244 ms 71424 KB Output is correct
35 Correct 247 ms 72068 KB Output is correct
36 Correct 245 ms 71740 KB Output is correct
37 Correct 257 ms 71752 KB Output is correct
38 Correct 251 ms 71636 KB Output is correct
39 Correct 250 ms 71644 KB Output is correct
40 Correct 255 ms 71896 KB Output is correct
41 Correct 251 ms 71628 KB Output is correct
42 Correct 251 ms 71856 KB Output is correct
43 Correct 96 ms 34596 KB Output is correct
44 Correct 137 ms 49072 KB Output is correct
45 Correct 137 ms 49856 KB Output is correct
46 Correct 140 ms 49232 KB Output is correct
47 Correct 251 ms 71880 KB Output is correct
48 Correct 253 ms 71868 KB Output is correct
49 Correct 258 ms 72444 KB Output is correct
50 Correct 249 ms 72136 KB Output is correct
51 Correct 255 ms 72556 KB Output is correct
52 Correct 261 ms 73556 KB Output is correct
53 Correct 254 ms 72388 KB Output is correct
54 Correct 254 ms 71980 KB Output is correct
55 Correct 230 ms 71644 KB Output is correct
56 Correct 233 ms 71696 KB Output is correct
57 Correct 238 ms 71632 KB Output is correct
58 Correct 244 ms 71628 KB Output is correct
59 Correct 244 ms 71968 KB Output is correct
60 Correct 245 ms 71776 KB Output is correct
61 Correct 253 ms 71976 KB Output is correct
62 Correct 258 ms 71944 KB Output is correct
63 Correct 254 ms 71860 KB Output is correct