Submission #441625

# Submission time Handle Problem Language Result Execution time Memory
441625 2021-07-05T15:18:17 Z Vladth11 Peru (RMI20_peru) C++14
100 / 100
529 ms 72880 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define debug(x) cerr << #x << " " << x << "\n"
#define debugs(x) cerr << #x << " " << x << " "
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include "peru.h"

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair <ll, ll> pii;
typedef pair <long double, pii> muchie;
typedef tree <ll, null_type, less_equal <ll>, rb_tree_tag, tree_order_statistics_node_update> OST;

const ll NMAX = 2500002;
const ll INF = (1LL << 60);
const ll HALF = (1LL << 59);
const ll MOD = 1000000007;
const ll BLOCK = 318;
const ll base = 31;
const ll nr_of_bits = 21;
const ll LIMIT = 1000;

ll dp[NMAX];
ll a[NMAX];
ll put[NMAX];
deque <ll> dq;

int solve(int n, int k, int* v) {
    ll sol = 0;
    for(ll i = 0; i < n; i++)
        a[i + 1] = v[i];
    put[0] = 1;
    for(ll i = 1; i <= n; i++) {
        put[i] = put[i - 1] * 23;
        put[i] %= MOD;
    }
    multiset <ll> st;
    for(ll i = 1; i <= n; i++) {
        while(dq.size() && dq.front() < i - k + 1) {
            ll x = dp[dq.front()];
            dq.pop_front();
            if(dq.size()){
                x += a[dq.front()];
                auto it = st.find(x);
                st.erase(it);
            }
        }
        while(dq.size() && a[dq.back()] <= a[i]) {
            ll x = a[dq.back()];
            dq.pop_back();
            if(dq.size()){
                x += dp[dq.back()];
                auto it = st.find(x);
                st.erase(it);
            }
        }
        if(dq.size())
            st.insert(a[i] + dp[dq.back()]);
        dq.push_back(i);
        if(st.size()) {
            dp[i] = min((ll)(*st.begin()), dp[max(i - k, 0LL)] + a[dq.front()]);
            //dp[i] %= MOD;
        } else {
            dp[i] = dp[max(0LL, i - k)] + a[dq.front()];
            //dp[i] %= MOD;
        }
        sol += ((dp[i] % MOD) * put[n - i]) % MOD;
        sol %= MOD;
    }
    return sol;
}

# 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 0 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 0 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 69 ms 11360 KB Output is correct
16 Correct 74 ms 11416 KB Output is correct
17 Correct 77 ms 11416 KB Output is correct
18 Correct 44 ms 11380 KB Output is correct
19 Correct 43 ms 11288 KB Output is correct
20 Correct 52 ms 11340 KB Output is correct
21 Correct 66 ms 11448 KB Output is correct
22 Correct 71 ms 11404 KB Output is correct
23 Correct 68 ms 11512 KB Output is correct
24 Correct 66 ms 11332 KB Output is correct
25 Correct 88 ms 11344 KB Output is correct
26 Correct 67 ms 11428 KB Output is correct
27 Correct 70 ms 11400 KB Output is correct
28 Correct 65 ms 11420 KB Output is correct
29 Correct 70 ms 11592 KB Output is correct
30 Correct 77 ms 11380 KB Output is correct
31 Correct 74 ms 11316 KB Output is correct
32 Correct 84 ms 11560 KB Output is correct
33 Correct 78 ms 11412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 11360 KB Output is correct
2 Correct 74 ms 11416 KB Output is correct
3 Correct 77 ms 11416 KB Output is correct
4 Correct 44 ms 11380 KB Output is correct
5 Correct 43 ms 11288 KB Output is correct
6 Correct 52 ms 11340 KB Output is correct
7 Correct 66 ms 11448 KB Output is correct
8 Correct 71 ms 11404 KB Output is correct
9 Correct 68 ms 11512 KB Output is correct
10 Correct 66 ms 11332 KB Output is correct
11 Correct 88 ms 11344 KB Output is correct
12 Correct 67 ms 11428 KB Output is correct
13 Correct 70 ms 11400 KB Output is correct
14 Correct 65 ms 11420 KB Output is correct
15 Correct 70 ms 11592 KB Output is correct
16 Correct 77 ms 11380 KB Output is correct
17 Correct 74 ms 11316 KB Output is correct
18 Correct 84 ms 11560 KB Output is correct
19 Correct 78 ms 11412 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 0 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 438 ms 68988 KB Output is correct
35 Correct 468 ms 69312 KB Output is correct
36 Correct 425 ms 69168 KB Output is correct
37 Correct 439 ms 69108 KB Output is correct
38 Correct 460 ms 69168 KB Output is correct
39 Correct 436 ms 69264 KB Output is correct
40 Correct 454 ms 69192 KB Output is correct
41 Correct 525 ms 69092 KB Output is correct
42 Correct 447 ms 69484 KB Output is correct
43 Correct 166 ms 28108 KB Output is correct
44 Correct 185 ms 41480 KB Output is correct
45 Correct 165 ms 41412 KB Output is correct
46 Correct 173 ms 41500 KB Output is correct
47 Correct 426 ms 69516 KB Output is correct
48 Correct 459 ms 69492 KB Output is correct
49 Correct 471 ms 69844 KB Output is correct
50 Correct 463 ms 71004 KB Output is correct
51 Correct 449 ms 70436 KB Output is correct
52 Correct 489 ms 72880 KB Output is correct
53 Correct 426 ms 71452 KB Output is correct
54 Correct 440 ms 69156 KB Output is correct
55 Correct 422 ms 69080 KB Output is correct
56 Correct 406 ms 69028 KB Output is correct
57 Correct 421 ms 69116 KB Output is correct
58 Correct 529 ms 69156 KB Output is correct
59 Correct 409 ms 69100 KB Output is correct
60 Correct 419 ms 69208 KB Output is correct
61 Correct 461 ms 69528 KB Output is correct
62 Correct 438 ms 69476 KB Output is correct
63 Correct 442 ms 69228 KB Output is correct