Submission #746397

# Submission time Handle Problem Language Result Execution time Memory
746397 2023-05-22T12:25:09 Z doowey Peru (RMI20_peru) C++14
100 / 100
356 ms 80152 KB
#include <bits/stdc++.h>
#include "peru.h"

using namespace std;

typedef long long ll;
typedef pair<ll, int> pii;

#define fi first
#define se second
#define mp make_pair

const int N = 2511111;
const int MOD = (int)1e9 + 7;
ll dp[N];
ll A[N];
ll ndp[N];
bool off[N];
int pos[N];


int solve(int n, int k, int* v){
    for(int i = 1; i <= n; i ++ ){
        A[i] = v[i - 1];
    }
    priority_queue<pii, vector<pii>, greater<pii>> P;
    deque<pii> L;
    //L.push_back(mp(0, -1));
    int id = 0;
    ll mx;
    for(int i = 1; i <= n; i ++ ){

        while(!L.empty() && A[i] >= A[L.back().fi]){
            if(L.back().se != -1) off[L.back().se] = true;
            L.pop_back();
        }

        while(!L.empty() && L.front().fi <= i - k) {
            if(L.front().se != -1) off[L.front().se] = true;
            L.pop_front();
        }
        if(!L.empty()){
            off[L.back().se] = true;
            P.push(mp(A[i] + dp[L.back().fi], id));
            L.back().se = id;
            id ++ ;
        }
        L.push_back(mp(i, -1));
        dp[i] = dp[max(i - k, 0)] + A[L.front().fi];
        while(!P.empty() && off[P.top().se]) P.pop();
        if(!P.empty()) {
            dp[i] = min(dp[i], P.top().fi);
        }
        // -------------
        /*
        ndp[i] = (ll)1e18;
        mx = 0ll;
        for(int j = i ; j >= max(1, i - k + 1); j -- ){
            mx = max(mx, A[j]);
            ndp[i] = min(ndp[i], ndp[j - 1] + mx);
        }
        */
    }
    int chum = 0;
    int pw = 1;
    for(int i = n; i >= 1; i -- ){
        //cout << dp[i] << " ";
        dp[i] %= MOD;
        chum += (pw * 1ll * dp[i]) % MOD;
        if(chum >= MOD) chum -= MOD;
        pw = (pw * 23ll) % MOD;
    }
    return chum;
}

Compilation message

peru.cpp: In function 'int solve(int, int, int*)':
peru.cpp:30:8: warning: unused variable 'mx' [-Wunused-variable]
   30 |     ll mx;
      |        ^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 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 340 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 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 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 340 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 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 44 ms 8636 KB Output is correct
16 Correct 44 ms 8604 KB Output is correct
17 Correct 45 ms 8608 KB Output is correct
18 Correct 45 ms 8604 KB Output is correct
19 Correct 47 ms 8688 KB Output is correct
20 Correct 44 ms 8712 KB Output is correct
21 Correct 46 ms 12748 KB Output is correct
22 Correct 50 ms 12812 KB Output is correct
23 Correct 50 ms 12932 KB Output is correct
24 Correct 48 ms 12812 KB Output is correct
25 Correct 49 ms 12804 KB Output is correct
26 Correct 48 ms 12740 KB Output is correct
27 Correct 50 ms 12760 KB Output is correct
28 Correct 55 ms 12856 KB Output is correct
29 Correct 49 ms 12916 KB Output is correct
30 Correct 47 ms 12852 KB Output is correct
31 Correct 48 ms 12712 KB Output is correct
32 Correct 46 ms 12936 KB Output is correct
33 Correct 45 ms 12772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 8636 KB Output is correct
2 Correct 44 ms 8604 KB Output is correct
3 Correct 45 ms 8608 KB Output is correct
4 Correct 45 ms 8604 KB Output is correct
5 Correct 47 ms 8688 KB Output is correct
6 Correct 44 ms 8712 KB Output is correct
7 Correct 46 ms 12748 KB Output is correct
8 Correct 50 ms 12812 KB Output is correct
9 Correct 50 ms 12932 KB Output is correct
10 Correct 48 ms 12812 KB Output is correct
11 Correct 49 ms 12804 KB Output is correct
12 Correct 48 ms 12740 KB Output is correct
13 Correct 50 ms 12760 KB Output is correct
14 Correct 55 ms 12856 KB Output is correct
15 Correct 49 ms 12916 KB Output is correct
16 Correct 47 ms 12852 KB Output is correct
17 Correct 48 ms 12712 KB Output is correct
18 Correct 46 ms 12936 KB Output is correct
19 Correct 45 ms 12772 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 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 340 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 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 294 ms 75468 KB Output is correct
35 Correct 287 ms 75644 KB Output is correct
36 Correct 294 ms 75604 KB Output is correct
37 Correct 290 ms 75584 KB Output is correct
38 Correct 320 ms 75604 KB Output is correct
39 Correct 306 ms 75680 KB Output is correct
40 Correct 303 ms 75672 KB Output is correct
41 Correct 298 ms 75628 KB Output is correct
42 Correct 295 ms 75788 KB Output is correct
43 Correct 117 ms 30668 KB Output is correct
44 Correct 177 ms 46580 KB Output is correct
45 Correct 173 ms 46564 KB Output is correct
46 Correct 179 ms 46656 KB Output is correct
47 Correct 306 ms 77764 KB Output is correct
48 Correct 307 ms 77964 KB Output is correct
49 Correct 316 ms 78256 KB Output is correct
50 Correct 319 ms 78684 KB Output is correct
51 Correct 322 ms 78820 KB Output is correct
52 Correct 322 ms 80152 KB Output is correct
53 Correct 356 ms 78936 KB Output is correct
54 Correct 303 ms 75568 KB Output is correct
55 Correct 282 ms 75708 KB Output is correct
56 Correct 286 ms 75548 KB Output is correct
57 Correct 296 ms 75592 KB Output is correct
58 Correct 288 ms 75620 KB Output is correct
59 Correct 306 ms 75544 KB Output is correct
60 Correct 283 ms 75584 KB Output is correct
61 Correct 324 ms 77976 KB Output is correct
62 Correct 310 ms 77828 KB Output is correct
63 Correct 314 ms 77648 KB Output is correct