# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1092699 |
2024-09-24T18:49:08 Z |
alexdd |
Peru (RMI20_peru) |
C++17 |
|
532 ms |
79840 KB |
#include "peru.h"
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9+7;
const long long INF = 1e18;
long long a[2500005];
long long dp[2500005];
multiset<long long> s;
int solve(int n, int k, int* v)
{
a[0]=2e9+2;
deque<pair<long long,long long>> dq;///{poz,mxm}
deque<int> sw;
dq.push_back({0,0});
s.insert(0);
for(int i=1;i<=n;i++)
{
a[i]=v[i-1];
while(!sw.empty() && sw.front() <= i-k)
sw.pop_front();
while(!sw.empty() && a[sw.back()] <= a[i])
sw.pop_back();
sw.push_back(i);
dp[i]=INF;
dp[i] = min(dp[i], dp[max(0,i-k)]+a[sw.front()]);
while(!dq.empty() && dq.front().first < i-k)
{
s.erase(s.find(dp[dq.front().first]+dq.front().second));
dq.pop_front();
}
int ult=-1;
while(!dq.empty() && a[i] > dq.back().second)
{
ult = dq.back().first;
s.erase(s.find(dp[dq.back().first]+dq.back().second));
dq.pop_back();
}
if(ult!=-1)
{
dq.push_back({ult,a[i]});
s.insert(dp[ult]+a[i]);
}
if(!s.empty()) dp[i] = min(dp[i], *s.begin());
dq.push_back({i,0});
s.insert(dp[i]);
}
long long rez=0,put23=1;
for(int i=n;i>0;i--)
{
rez = (rez + dp[i]%MOD*put23)%MOD;
put23 = put23*23LL%MOD;
}
return rez;
}
/*
8 3
3 2 9 8 7 11 3 4
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
70 ms |
12368 KB |
Output is correct |
16 |
Correct |
70 ms |
12368 KB |
Output is correct |
17 |
Correct |
88 ms |
12368 KB |
Output is correct |
18 |
Correct |
46 ms |
12368 KB |
Output is correct |
19 |
Correct |
54 ms |
12312 KB |
Output is correct |
20 |
Correct |
46 ms |
12264 KB |
Output is correct |
21 |
Correct |
75 ms |
12388 KB |
Output is correct |
22 |
Correct |
78 ms |
12368 KB |
Output is correct |
23 |
Correct |
75 ms |
12628 KB |
Output is correct |
24 |
Correct |
73 ms |
12508 KB |
Output is correct |
25 |
Correct |
75 ms |
12368 KB |
Output is correct |
26 |
Correct |
71 ms |
12400 KB |
Output is correct |
27 |
Correct |
70 ms |
12428 KB |
Output is correct |
28 |
Correct |
69 ms |
12372 KB |
Output is correct |
29 |
Correct |
71 ms |
12628 KB |
Output is correct |
30 |
Correct |
76 ms |
12436 KB |
Output is correct |
31 |
Correct |
72 ms |
12368 KB |
Output is correct |
32 |
Correct |
72 ms |
12628 KB |
Output is correct |
33 |
Correct |
75 ms |
12368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
70 ms |
12368 KB |
Output is correct |
2 |
Correct |
70 ms |
12368 KB |
Output is correct |
3 |
Correct |
88 ms |
12368 KB |
Output is correct |
4 |
Correct |
46 ms |
12368 KB |
Output is correct |
5 |
Correct |
54 ms |
12312 KB |
Output is correct |
6 |
Correct |
46 ms |
12264 KB |
Output is correct |
7 |
Correct |
75 ms |
12388 KB |
Output is correct |
8 |
Correct |
78 ms |
12368 KB |
Output is correct |
9 |
Correct |
75 ms |
12628 KB |
Output is correct |
10 |
Correct |
73 ms |
12508 KB |
Output is correct |
11 |
Correct |
75 ms |
12368 KB |
Output is correct |
12 |
Correct |
71 ms |
12400 KB |
Output is correct |
13 |
Correct |
70 ms |
12428 KB |
Output is correct |
14 |
Correct |
69 ms |
12372 KB |
Output is correct |
15 |
Correct |
71 ms |
12628 KB |
Output is correct |
16 |
Correct |
76 ms |
12436 KB |
Output is correct |
17 |
Correct |
72 ms |
12368 KB |
Output is correct |
18 |
Correct |
72 ms |
12628 KB |
Output is correct |
19 |
Correct |
75 ms |
12368 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
344 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
470 ms |
73036 KB |
Output is correct |
35 |
Correct |
488 ms |
73448 KB |
Output is correct |
36 |
Correct |
476 ms |
73292 KB |
Output is correct |
37 |
Correct |
498 ms |
73360 KB |
Output is correct |
38 |
Correct |
500 ms |
73248 KB |
Output is correct |
39 |
Correct |
500 ms |
73548 KB |
Output is correct |
40 |
Correct |
506 ms |
73296 KB |
Output is correct |
41 |
Correct |
501 ms |
73296 KB |
Output is correct |
42 |
Correct |
508 ms |
73556 KB |
Output is correct |
43 |
Correct |
180 ms |
29776 KB |
Output is correct |
44 |
Correct |
182 ms |
45140 KB |
Output is correct |
45 |
Correct |
180 ms |
45140 KB |
Output is correct |
46 |
Correct |
174 ms |
45140 KB |
Output is correct |
47 |
Correct |
493 ms |
75556 KB |
Output is correct |
48 |
Correct |
502 ms |
75520 KB |
Output is correct |
49 |
Correct |
510 ms |
76188 KB |
Output is correct |
50 |
Correct |
466 ms |
77652 KB |
Output is correct |
51 |
Correct |
504 ms |
76860 KB |
Output is correct |
52 |
Correct |
503 ms |
79840 KB |
Output is correct |
53 |
Correct |
500 ms |
78160 KB |
Output is correct |
54 |
Correct |
514 ms |
73216 KB |
Output is correct |
55 |
Correct |
448 ms |
72764 KB |
Output is correct |
56 |
Correct |
459 ms |
73220 KB |
Output is correct |
57 |
Correct |
460 ms |
73192 KB |
Output is correct |
58 |
Correct |
463 ms |
73284 KB |
Output is correct |
59 |
Correct |
486 ms |
73156 KB |
Output is correct |
60 |
Correct |
481 ms |
73300 KB |
Output is correct |
61 |
Correct |
529 ms |
75800 KB |
Output is correct |
62 |
Correct |
532 ms |
75728 KB |
Output is correct |
63 |
Correct |
516 ms |
75204 KB |
Output is correct |