# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
533959 |
2022-03-07T18:04:53 Z |
amunduzbaev |
Peru (RMI20_peru) |
C++17 |
|
238 ms |
27076 KB |
#include "bits/stdc++.h"
using namespace std;
#include "peru.h"
#ifndef EVAL
#include "grader.cpp"
#endif
#define ar array
const int N = 4e5 + 5;
const int mod = 1e9 + 7;
const int P = 23;
long long dp[N];
int solve(int n, int k, int* a){
deque<int> ss;
multiset<long long> mm;
int res = 0;
for(int i=0;i<n;i++){
while(!ss.empty() && ss.front() <= i - k){
int j = ss.front(); ss.pop_front();
if(!ss.empty()){
if(mm.count(dp[j] + a[ss.front()]))
mm.erase(mm.find(dp[j] + a[ss.front()]));
}
}
while(!ss.empty() && a[ss.back()] <= a[i]){
int j = ss.back(); ss.pop_back();
if(!ss.empty()){
if(mm.count(dp[ss.back()] + a[j]))
mm.erase(mm.find(dp[ss.back()] + a[j]));
}
}
dp[i] = 1e18;
if(!ss.empty()) mm.insert(dp[ss.back()] + a[i]);
ss.push_back(i);
if(!mm.empty()) dp[i] = *mm.begin();
//~ assert(!ss.empty());
dp[i] = min(dp[i], (i < k ? 0 : dp[i-k]) + a[ss.front()]);
res = (res * 1ll * P + dp[i]) % mod;
}
//~ cout<<"\n";
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
69 ms |
5112 KB |
Output is correct |
16 |
Correct |
71 ms |
5096 KB |
Output is correct |
17 |
Correct |
71 ms |
5028 KB |
Output is correct |
18 |
Correct |
45 ms |
4988 KB |
Output is correct |
19 |
Correct |
46 ms |
5048 KB |
Output is correct |
20 |
Correct |
45 ms |
5092 KB |
Output is correct |
21 |
Correct |
71 ms |
5068 KB |
Output is correct |
22 |
Correct |
69 ms |
5100 KB |
Output is correct |
23 |
Correct |
72 ms |
5180 KB |
Output is correct |
24 |
Correct |
85 ms |
5112 KB |
Output is correct |
25 |
Correct |
73 ms |
5124 KB |
Output is correct |
26 |
Correct |
76 ms |
5064 KB |
Output is correct |
27 |
Correct |
77 ms |
5148 KB |
Output is correct |
28 |
Correct |
84 ms |
5224 KB |
Output is correct |
29 |
Correct |
67 ms |
5296 KB |
Output is correct |
30 |
Correct |
71 ms |
5136 KB |
Output is correct |
31 |
Correct |
69 ms |
5072 KB |
Output is correct |
32 |
Correct |
70 ms |
5140 KB |
Output is correct |
33 |
Correct |
68 ms |
5004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
69 ms |
5112 KB |
Output is correct |
2 |
Correct |
71 ms |
5096 KB |
Output is correct |
3 |
Correct |
71 ms |
5028 KB |
Output is correct |
4 |
Correct |
45 ms |
4988 KB |
Output is correct |
5 |
Correct |
46 ms |
5048 KB |
Output is correct |
6 |
Correct |
45 ms |
5092 KB |
Output is correct |
7 |
Correct |
71 ms |
5068 KB |
Output is correct |
8 |
Correct |
69 ms |
5100 KB |
Output is correct |
9 |
Correct |
72 ms |
5180 KB |
Output is correct |
10 |
Correct |
85 ms |
5112 KB |
Output is correct |
11 |
Correct |
73 ms |
5124 KB |
Output is correct |
12 |
Correct |
76 ms |
5064 KB |
Output is correct |
13 |
Correct |
77 ms |
5148 KB |
Output is correct |
14 |
Correct |
84 ms |
5224 KB |
Output is correct |
15 |
Correct |
67 ms |
5296 KB |
Output is correct |
16 |
Correct |
71 ms |
5136 KB |
Output is correct |
17 |
Correct |
69 ms |
5072 KB |
Output is correct |
18 |
Correct |
70 ms |
5140 KB |
Output is correct |
19 |
Correct |
68 ms |
5004 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Runtime error |
238 ms |
27076 KB |
Execution killed with signal 11 |
35 |
Halted |
0 ms |
0 KB |
- |