#include <bits/stdc++.h>
#include "peru.h"
using namespace std;
const int NMAX = 2500000;
const int MOD = 1e9 + 7;
long long dp[NMAX];
int solve( int n, int k, int* v ) {
deque <int> dq;
int ans = 0;
for ( int i = 0; i < n; i ++ ) {
while ( !dq.empty() && v[dq.back()] <= v[i] ) dq.pop_back();
dq.push_back( i );
if ( dq.front() <= i - k ) dq.pop_front();
dp[i] = v[dq.front()] + ( i >= k ? dp[i - k] : 0 );
for ( int j = 1; j < (int)dq.size(); j ++ ) {
dp[i] = min( dp[i], dp[dq[j - 1]] + v[dq[j]] );
}
ans = ( (long long)ans * 23 + dp[i] ) % MOD;
}
dq.clear();
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
217 ms |
8824 KB |
Output is correct |
16 |
Correct |
224 ms |
8936 KB |
Output is correct |
17 |
Correct |
238 ms |
8788 KB |
Output is correct |
18 |
Correct |
17 ms |
8792 KB |
Output is correct |
19 |
Correct |
17 ms |
8796 KB |
Output is correct |
20 |
Correct |
20 ms |
8796 KB |
Output is correct |
21 |
Correct |
326 ms |
13256 KB |
Output is correct |
22 |
Execution timed out |
923 ms |
13144 KB |
Time limit exceeded |
23 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
217 ms |
8824 KB |
Output is correct |
2 |
Correct |
224 ms |
8936 KB |
Output is correct |
3 |
Correct |
238 ms |
8788 KB |
Output is correct |
4 |
Correct |
17 ms |
8792 KB |
Output is correct |
5 |
Correct |
17 ms |
8796 KB |
Output is correct |
6 |
Correct |
20 ms |
8796 KB |
Output is correct |
7 |
Correct |
326 ms |
13256 KB |
Output is correct |
8 |
Execution timed out |
923 ms |
13144 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |