#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;
for(int i = 1; i <= n; i++){
ans *= 23;
ans += dp[i];
ans %= MOD;
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6612 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6488 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6612 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6488 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 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 |
46 ms |
19244 KB |
Output is correct |
16 |
Correct |
45 ms |
18976 KB |
Output is correct |
17 |
Correct |
47 ms |
18960 KB |
Output is correct |
18 |
Correct |
35 ms |
19200 KB |
Output is correct |
19 |
Correct |
34 ms |
19184 KB |
Output is correct |
20 |
Correct |
37 ms |
18944 KB |
Output is correct |
21 |
Correct |
49 ms |
19232 KB |
Output is correct |
22 |
Correct |
48 ms |
19276 KB |
Output is correct |
23 |
Correct |
46 ms |
19300 KB |
Output is correct |
24 |
Correct |
47 ms |
19036 KB |
Output is correct |
25 |
Correct |
46 ms |
19028 KB |
Output is correct |
26 |
Correct |
46 ms |
19224 KB |
Output is correct |
27 |
Correct |
57 ms |
19248 KB |
Output is correct |
28 |
Correct |
45 ms |
19304 KB |
Output is correct |
29 |
Correct |
42 ms |
19216 KB |
Output is correct |
30 |
Correct |
59 ms |
19236 KB |
Output is correct |
31 |
Correct |
45 ms |
19216 KB |
Output is correct |
32 |
Correct |
45 ms |
19600 KB |
Output is correct |
33 |
Correct |
46 ms |
19036 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
46 ms |
19244 KB |
Output is correct |
2 |
Correct |
45 ms |
18976 KB |
Output is correct |
3 |
Correct |
47 ms |
18960 KB |
Output is correct |
4 |
Correct |
35 ms |
19200 KB |
Output is correct |
5 |
Correct |
34 ms |
19184 KB |
Output is correct |
6 |
Correct |
37 ms |
18944 KB |
Output is correct |
7 |
Correct |
49 ms |
19232 KB |
Output is correct |
8 |
Correct |
48 ms |
19276 KB |
Output is correct |
9 |
Correct |
46 ms |
19300 KB |
Output is correct |
10 |
Correct |
47 ms |
19036 KB |
Output is correct |
11 |
Correct |
46 ms |
19028 KB |
Output is correct |
12 |
Correct |
46 ms |
19224 KB |
Output is correct |
13 |
Correct |
57 ms |
19248 KB |
Output is correct |
14 |
Correct |
45 ms |
19304 KB |
Output is correct |
15 |
Correct |
42 ms |
19216 KB |
Output is correct |
16 |
Correct |
59 ms |
19236 KB |
Output is correct |
17 |
Correct |
45 ms |
19216 KB |
Output is correct |
18 |
Correct |
45 ms |
19600 KB |
Output is correct |
19 |
Correct |
46 ms |
19036 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 |
6492 KB |
Output is correct |
23 |
Correct |
1 ms |
6492 KB |
Output is correct |
24 |
Correct |
1 ms |
6492 KB |
Output is correct |
25 |
Correct |
1 ms |
6612 KB |
Output is correct |
26 |
Correct |
1 ms |
6492 KB |
Output is correct |
27 |
Correct |
1 ms |
6492 KB |
Output is correct |
28 |
Correct |
1 ms |
6488 KB |
Output is correct |
29 |
Correct |
1 ms |
6492 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 |
293 ms |
69136 KB |
Output is correct |
35 |
Correct |
301 ms |
69188 KB |
Output is correct |
36 |
Correct |
288 ms |
69156 KB |
Output is correct |
37 |
Correct |
306 ms |
69168 KB |
Output is correct |
38 |
Correct |
307 ms |
69332 KB |
Output is correct |
39 |
Correct |
296 ms |
69460 KB |
Output is correct |
40 |
Correct |
299 ms |
69348 KB |
Output is correct |
41 |
Correct |
292 ms |
69280 KB |
Output is correct |
42 |
Correct |
317 ms |
69460 KB |
Output is correct |
43 |
Correct |
110 ms |
35912 KB |
Output is correct |
44 |
Correct |
124 ms |
49928 KB |
Output is correct |
45 |
Correct |
121 ms |
49936 KB |
Output is correct |
46 |
Correct |
132 ms |
49968 KB |
Output is correct |
47 |
Correct |
286 ms |
69548 KB |
Output is correct |
48 |
Correct |
303 ms |
69588 KB |
Output is correct |
49 |
Correct |
296 ms |
69972 KB |
Output is correct |
50 |
Correct |
292 ms |
70976 KB |
Output is correct |
51 |
Correct |
298 ms |
70564 KB |
Output is correct |
52 |
Correct |
292 ms |
72748 KB |
Output is correct |
53 |
Correct |
299 ms |
71376 KB |
Output is correct |
54 |
Correct |
321 ms |
69284 KB |
Output is correct |
55 |
Correct |
269 ms |
69360 KB |
Output is correct |
56 |
Correct |
267 ms |
69184 KB |
Output is correct |
57 |
Correct |
268 ms |
69164 KB |
Output is correct |
58 |
Correct |
277 ms |
69284 KB |
Output is correct |
59 |
Correct |
280 ms |
69240 KB |
Output is correct |
60 |
Correct |
282 ms |
69256 KB |
Output is correct |
61 |
Correct |
315 ms |
69444 KB |
Output is correct |
62 |
Correct |
323 ms |
69620 KB |
Output is correct |
63 |
Correct |
327 ms |
69444 KB |
Output is correct |