# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
849380 |
2023-09-14T14:39:06 Z |
TahirAliyev |
Peru (RMI20_peru) |
C++17 |
|
328 ms |
98236 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, MOD = 1e9 + 7;
ll arr[MAX];
ll dp[MAX];
ll val[MAX];
multiset<ll> s;
deque<int> dq;
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) s.erase(s.find(val[dq.back()]));
dq.pop_back();
}
if(dq.size() && dq.front() == i - k){
dq.pop_front();
if(dq.size()){
s.erase(s.find(val[dq.front()]));
}
}
dp[i] = oo;
if(dq.size()){
val[i] = dp[dq.back()] + arr[i];
s.insert(val[i]);
dp[i] = *s.begin();
}
dq.push_back(i);
dp[i] = min(dp[i], arr[dq.front()] + dp[max(0, i - k)]);
}
ll ans = 0;
ll p = 1;
for(int i = n; i >= 1; i--){
ans += dp[i] % MOD * p % MOD;
ans %= MOD;
p *= 23;
p %= MOD;
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6576 KB |
Output is correct |
4 |
Correct |
1 ms |
6488 KB |
Output is correct |
5 |
Correct |
1 ms |
6488 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6652 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6612 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6576 KB |
Output is correct |
4 |
Correct |
1 ms |
6488 KB |
Output is correct |
5 |
Correct |
1 ms |
6488 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6652 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6612 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
49 ms |
23312 KB |
Output is correct |
16 |
Correct |
47 ms |
23300 KB |
Output is correct |
17 |
Correct |
48 ms |
23544 KB |
Output is correct |
18 |
Correct |
35 ms |
23120 KB |
Output is correct |
19 |
Correct |
35 ms |
23028 KB |
Output is correct |
20 |
Correct |
36 ms |
23124 KB |
Output is correct |
21 |
Correct |
47 ms |
23124 KB |
Output is correct |
22 |
Correct |
49 ms |
23472 KB |
Output is correct |
23 |
Correct |
48 ms |
23376 KB |
Output is correct |
24 |
Correct |
48 ms |
23076 KB |
Output is correct |
25 |
Correct |
48 ms |
23300 KB |
Output is correct |
26 |
Correct |
47 ms |
23336 KB |
Output is correct |
27 |
Correct |
47 ms |
23376 KB |
Output is correct |
28 |
Correct |
47 ms |
23616 KB |
Output is correct |
29 |
Correct |
45 ms |
23468 KB |
Output is correct |
30 |
Correct |
47 ms |
23220 KB |
Output is correct |
31 |
Correct |
52 ms |
23220 KB |
Output is correct |
32 |
Correct |
47 ms |
23412 KB |
Output is correct |
33 |
Correct |
47 ms |
23288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
23312 KB |
Output is correct |
2 |
Correct |
47 ms |
23300 KB |
Output is correct |
3 |
Correct |
48 ms |
23544 KB |
Output is correct |
4 |
Correct |
35 ms |
23120 KB |
Output is correct |
5 |
Correct |
35 ms |
23028 KB |
Output is correct |
6 |
Correct |
36 ms |
23124 KB |
Output is correct |
7 |
Correct |
47 ms |
23124 KB |
Output is correct |
8 |
Correct |
49 ms |
23472 KB |
Output is correct |
9 |
Correct |
48 ms |
23376 KB |
Output is correct |
10 |
Correct |
48 ms |
23076 KB |
Output is correct |
11 |
Correct |
48 ms |
23300 KB |
Output is correct |
12 |
Correct |
47 ms |
23336 KB |
Output is correct |
13 |
Correct |
47 ms |
23376 KB |
Output is correct |
14 |
Correct |
47 ms |
23616 KB |
Output is correct |
15 |
Correct |
45 ms |
23468 KB |
Output is correct |
16 |
Correct |
47 ms |
23220 KB |
Output is correct |
17 |
Correct |
52 ms |
23220 KB |
Output is correct |
18 |
Correct |
47 ms |
23412 KB |
Output is correct |
19 |
Correct |
47 ms |
23288 KB |
Output is correct |
20 |
Correct |
1 ms |
6492 KB |
Output is correct |
21 |
Correct |
1 ms |
6492 KB |
Output is correct |
22 |
Correct |
1 ms |
6576 KB |
Output is correct |
23 |
Correct |
1 ms |
6488 KB |
Output is correct |
24 |
Correct |
1 ms |
6488 KB |
Output is correct |
25 |
Correct |
1 ms |
6492 KB |
Output is correct |
26 |
Correct |
1 ms |
6652 KB |
Output is correct |
27 |
Correct |
1 ms |
6492 KB |
Output is correct |
28 |
Correct |
1 ms |
6492 KB |
Output is correct |
29 |
Correct |
1 ms |
6612 KB |
Output is correct |
30 |
Correct |
1 ms |
6492 KB |
Output is correct |
31 |
Correct |
1 ms |
6492 KB |
Output is correct |
32 |
Correct |
1 ms |
6492 KB |
Output is correct |
33 |
Correct |
1 ms |
6492 KB |
Output is correct |
34 |
Correct |
303 ms |
92596 KB |
Output is correct |
35 |
Correct |
298 ms |
92796 KB |
Output is correct |
36 |
Correct |
299 ms |
92848 KB |
Output is correct |
37 |
Correct |
301 ms |
92756 KB |
Output is correct |
38 |
Correct |
303 ms |
92852 KB |
Output is correct |
39 |
Correct |
302 ms |
92856 KB |
Output is correct |
40 |
Correct |
312 ms |
92704 KB |
Output is correct |
41 |
Correct |
308 ms |
92788 KB |
Output is correct |
42 |
Correct |
328 ms |
93000 KB |
Output is correct |
43 |
Correct |
113 ms |
45380 KB |
Output is correct |
44 |
Correct |
127 ms |
65196 KB |
Output is correct |
45 |
Correct |
130 ms |
65196 KB |
Output is correct |
46 |
Correct |
127 ms |
65064 KB |
Output is correct |
47 |
Correct |
302 ms |
95012 KB |
Output is correct |
48 |
Correct |
313 ms |
95132 KB |
Output is correct |
49 |
Correct |
305 ms |
95504 KB |
Output is correct |
50 |
Correct |
292 ms |
96544 KB |
Output is correct |
51 |
Correct |
304 ms |
96016 KB |
Output is correct |
52 |
Correct |
302 ms |
98236 KB |
Output is correct |
53 |
Correct |
306 ms |
96924 KB |
Output is correct |
54 |
Correct |
304 ms |
92792 KB |
Output is correct |
55 |
Correct |
278 ms |
92676 KB |
Output is correct |
56 |
Correct |
278 ms |
92700 KB |
Output is correct |
57 |
Correct |
283 ms |
92792 KB |
Output is correct |
58 |
Correct |
287 ms |
92736 KB |
Output is correct |
59 |
Correct |
289 ms |
92756 KB |
Output is correct |
60 |
Correct |
298 ms |
92796 KB |
Output is correct |
61 |
Correct |
323 ms |
95152 KB |
Output is correct |
62 |
Correct |
318 ms |
95296 KB |
Output is correct |
63 |
Correct |
314 ms |
94752 KB |
Output is correct |