# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
441633 |
2021-07-05T15:29:09 Z |
Vladth11 |
Peru (RMI20_peru) |
C++14 |
|
540 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 << " "
#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 |
344 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 |
296 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 |
344 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 |
296 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 |
65 ms |
11376 KB |
Output is correct |
16 |
Correct |
71 ms |
11380 KB |
Output is correct |
17 |
Correct |
65 ms |
11392 KB |
Output is correct |
18 |
Correct |
52 ms |
11368 KB |
Output is correct |
19 |
Correct |
45 ms |
11292 KB |
Output is correct |
20 |
Correct |
44 ms |
11400 KB |
Output is correct |
21 |
Correct |
77 ms |
11416 KB |
Output is correct |
22 |
Correct |
66 ms |
11420 KB |
Output is correct |
23 |
Correct |
64 ms |
11424 KB |
Output is correct |
24 |
Correct |
63 ms |
11400 KB |
Output is correct |
25 |
Correct |
63 ms |
11388 KB |
Output is correct |
26 |
Correct |
59 ms |
11400 KB |
Output is correct |
27 |
Correct |
62 ms |
11344 KB |
Output is correct |
28 |
Correct |
66 ms |
11456 KB |
Output is correct |
29 |
Correct |
61 ms |
11684 KB |
Output is correct |
30 |
Correct |
64 ms |
11396 KB |
Output is correct |
31 |
Correct |
72 ms |
11392 KB |
Output is correct |
32 |
Correct |
61 ms |
11488 KB |
Output is correct |
33 |
Correct |
65 ms |
11392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
11376 KB |
Output is correct |
2 |
Correct |
71 ms |
11380 KB |
Output is correct |
3 |
Correct |
65 ms |
11392 KB |
Output is correct |
4 |
Correct |
52 ms |
11368 KB |
Output is correct |
5 |
Correct |
45 ms |
11292 KB |
Output is correct |
6 |
Correct |
44 ms |
11400 KB |
Output is correct |
7 |
Correct |
77 ms |
11416 KB |
Output is correct |
8 |
Correct |
66 ms |
11420 KB |
Output is correct |
9 |
Correct |
64 ms |
11424 KB |
Output is correct |
10 |
Correct |
63 ms |
11400 KB |
Output is correct |
11 |
Correct |
63 ms |
11388 KB |
Output is correct |
12 |
Correct |
59 ms |
11400 KB |
Output is correct |
13 |
Correct |
62 ms |
11344 KB |
Output is correct |
14 |
Correct |
66 ms |
11456 KB |
Output is correct |
15 |
Correct |
61 ms |
11684 KB |
Output is correct |
16 |
Correct |
64 ms |
11396 KB |
Output is correct |
17 |
Correct |
72 ms |
11392 KB |
Output is correct |
18 |
Correct |
61 ms |
11488 KB |
Output is correct |
19 |
Correct |
65 ms |
11392 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
344 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 |
296 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 |
419 ms |
68904 KB |
Output is correct |
35 |
Correct |
432 ms |
69300 KB |
Output is correct |
36 |
Correct |
477 ms |
69160 KB |
Output is correct |
37 |
Correct |
414 ms |
69096 KB |
Output is correct |
38 |
Correct |
443 ms |
69240 KB |
Output is correct |
39 |
Correct |
423 ms |
69344 KB |
Output is correct |
40 |
Correct |
434 ms |
69204 KB |
Output is correct |
41 |
Correct |
431 ms |
69104 KB |
Output is correct |
42 |
Correct |
540 ms |
69300 KB |
Output is correct |
43 |
Correct |
161 ms |
28080 KB |
Output is correct |
44 |
Correct |
160 ms |
41412 KB |
Output is correct |
45 |
Correct |
166 ms |
41416 KB |
Output is correct |
46 |
Correct |
225 ms |
41448 KB |
Output is correct |
47 |
Correct |
410 ms |
69352 KB |
Output is correct |
48 |
Correct |
425 ms |
69568 KB |
Output is correct |
49 |
Correct |
432 ms |
69924 KB |
Output is correct |
50 |
Correct |
416 ms |
71028 KB |
Output is correct |
51 |
Correct |
435 ms |
70512 KB |
Output is correct |
52 |
Correct |
432 ms |
72880 KB |
Output is correct |
53 |
Correct |
522 ms |
71500 KB |
Output is correct |
54 |
Correct |
415 ms |
69080 KB |
Output is correct |
55 |
Correct |
378 ms |
68996 KB |
Output is correct |
56 |
Correct |
388 ms |
69096 KB |
Output is correct |
57 |
Correct |
388 ms |
69176 KB |
Output is correct |
58 |
Correct |
400 ms |
69316 KB |
Output is correct |
59 |
Correct |
404 ms |
69144 KB |
Output is correct |
60 |
Correct |
427 ms |
69208 KB |
Output is correct |
61 |
Correct |
452 ms |
69508 KB |
Output is correct |
62 |
Correct |
460 ms |
69580 KB |
Output is correct |
63 |
Correct |
423 ms |
69252 KB |
Output is correct |