#include "peru.h"
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <vector>
#include <queue>
#include <stack>
#include <set>
typedef long long llong;
const int MAXN = 2500000 + 10;
const int MOD = 1e9 + 7;
const llong INF = 1e18;
const int INTINF = 1e9;
int n, k;
int a[MAXN];
llong dp[MAXN];
std::deque <int> dq;
std::multiset <llong> ms;
int prev[MAXN];
int solve(int N, int K, int* v)
{
n = N; k = K;
for (int i = 1 ; i <= n ; ++i)
{
a[i] = v[i - 1];
}
a[0] = INTINF;
dp[0] = 0;
for (int i = 1 ; i <= n ; ++i)
{
if (dq.size() && dq[0] == i - k)
{
if (dq.size() >= 2)
{
ms.erase(ms.find(a[dq[1]] + dp[dq[0]]));
}
dq.pop_front();
}
while (dq.size() && a[i] > a[dq.back()])
{
if (dq.size() >= 2)
{
ms.erase(ms.find(a[dq.back()] + dp[dq[dq.size() - 2]]));
}
dq.pop_back();
}
if (dq.size())
{
ms.insert(dp[dq.back()] + a[i]);
}
dq.push_back(i);
dp[i] = INF;
if (ms.size()) dp[i] = (*ms.begin());
dp[i] = std::min(dp[i], dp[std::max(0, i - k)] + a[dq[0]]);
}
int ans = 0;
for (int i = 1 ; i <= n ; ++i)
{
ans = (1LL * ans * 23 + dp[i]) % 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 |
6488 KB |
Output is correct |
4 |
Correct |
1 ms |
6488 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 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 |
6492 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 |
6488 KB |
Output is correct |
4 |
Correct |
1 ms |
6488 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 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 |
6492 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 |
47 ms |
12656 KB |
Output is correct |
16 |
Correct |
45 ms |
12892 KB |
Output is correct |
17 |
Correct |
46 ms |
12876 KB |
Output is correct |
18 |
Correct |
33 ms |
12624 KB |
Output is correct |
19 |
Correct |
33 ms |
12624 KB |
Output is correct |
20 |
Correct |
33 ms |
12620 KB |
Output is correct |
21 |
Correct |
47 ms |
16976 KB |
Output is correct |
22 |
Correct |
53 ms |
17232 KB |
Output is correct |
23 |
Correct |
48 ms |
16976 KB |
Output is correct |
24 |
Correct |
47 ms |
16752 KB |
Output is correct |
25 |
Correct |
47 ms |
16976 KB |
Output is correct |
26 |
Correct |
49 ms |
16980 KB |
Output is correct |
27 |
Correct |
47 ms |
17020 KB |
Output is correct |
28 |
Correct |
46 ms |
17056 KB |
Output is correct |
29 |
Correct |
43 ms |
17236 KB |
Output is correct |
30 |
Correct |
47 ms |
16996 KB |
Output is correct |
31 |
Correct |
48 ms |
16968 KB |
Output is correct |
32 |
Correct |
47 ms |
16980 KB |
Output is correct |
33 |
Correct |
47 ms |
16720 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
12656 KB |
Output is correct |
2 |
Correct |
45 ms |
12892 KB |
Output is correct |
3 |
Correct |
46 ms |
12876 KB |
Output is correct |
4 |
Correct |
33 ms |
12624 KB |
Output is correct |
5 |
Correct |
33 ms |
12624 KB |
Output is correct |
6 |
Correct |
33 ms |
12620 KB |
Output is correct |
7 |
Correct |
47 ms |
16976 KB |
Output is correct |
8 |
Correct |
53 ms |
17232 KB |
Output is correct |
9 |
Correct |
48 ms |
16976 KB |
Output is correct |
10 |
Correct |
47 ms |
16752 KB |
Output is correct |
11 |
Correct |
47 ms |
16976 KB |
Output is correct |
12 |
Correct |
49 ms |
16980 KB |
Output is correct |
13 |
Correct |
47 ms |
17020 KB |
Output is correct |
14 |
Correct |
46 ms |
17056 KB |
Output is correct |
15 |
Correct |
43 ms |
17236 KB |
Output is correct |
16 |
Correct |
47 ms |
16996 KB |
Output is correct |
17 |
Correct |
48 ms |
16968 KB |
Output is correct |
18 |
Correct |
47 ms |
16980 KB |
Output is correct |
19 |
Correct |
47 ms |
16720 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 |
6488 KB |
Output is correct |
23 |
Correct |
1 ms |
6488 KB |
Output is correct |
24 |
Correct |
1 ms |
6492 KB |
Output is correct |
25 |
Correct |
1 ms |
6492 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 |
6492 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 |
296 ms |
64596 KB |
Output is correct |
35 |
Correct |
291 ms |
65036 KB |
Output is correct |
36 |
Correct |
292 ms |
64852 KB |
Output is correct |
37 |
Correct |
301 ms |
64884 KB |
Output is correct |
38 |
Correct |
307 ms |
65108 KB |
Output is correct |
39 |
Correct |
300 ms |
64832 KB |
Output is correct |
40 |
Correct |
311 ms |
64944 KB |
Output is correct |
41 |
Correct |
301 ms |
64840 KB |
Output is correct |
42 |
Correct |
312 ms |
64864 KB |
Output is correct |
43 |
Correct |
112 ms |
32696 KB |
Output is correct |
44 |
Correct |
127 ms |
46532 KB |
Output is correct |
45 |
Correct |
128 ms |
46660 KB |
Output is correct |
46 |
Correct |
125 ms |
46420 KB |
Output is correct |
47 |
Correct |
303 ms |
67144 KB |
Output is correct |
48 |
Correct |
304 ms |
67248 KB |
Output is correct |
49 |
Correct |
306 ms |
67944 KB |
Output is correct |
50 |
Correct |
286 ms |
68684 KB |
Output is correct |
51 |
Correct |
309 ms |
67924 KB |
Output is correct |
52 |
Correct |
299 ms |
70332 KB |
Output is correct |
53 |
Correct |
307 ms |
69304 KB |
Output is correct |
54 |
Correct |
300 ms |
65112 KB |
Output is correct |
55 |
Correct |
278 ms |
64576 KB |
Output is correct |
56 |
Correct |
286 ms |
64740 KB |
Output is correct |
57 |
Correct |
280 ms |
64844 KB |
Output is correct |
58 |
Correct |
288 ms |
64712 KB |
Output is correct |
59 |
Correct |
289 ms |
64860 KB |
Output is correct |
60 |
Correct |
292 ms |
64856 KB |
Output is correct |
61 |
Correct |
331 ms |
67668 KB |
Output is correct |
62 |
Correct |
317 ms |
67232 KB |
Output is correct |
63 |
Correct |
314 ms |
67436 KB |
Output is correct |