Submission #533991

# Submission time Handle Problem Language Result Execution time Memory
533991 2022-03-07T18:45:35 Z amunduzbaev Peru (RMI20_peru) C++17
100 / 100
496 ms 33672 KB
#include "bits/stdc++.h"
using namespace std;
#include "peru.h"
#ifndef EVAL
#include "grader.cpp"
#endif
 
#define ar array
#define int long long
#define i32 int32_t
const int N = 25e5 + 5;
const int mod = 1e9 + 7;
const int P = 23;
int dp[N];
 
i32 solve(i32 n, i32 k, i32* a){
	deque<int> ss;
	multiset<int> mm;
	i32 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 ? 0ll : 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 0 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 0 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 5056 KB Output is correct
16 Correct 69 ms 5040 KB Output is correct
17 Correct 69 ms 5068 KB Output is correct
18 Correct 48 ms 5000 KB Output is correct
19 Correct 44 ms 5108 KB Output is correct
20 Correct 43 ms 5120 KB Output is correct
21 Correct 67 ms 5044 KB Output is correct
22 Correct 84 ms 5184 KB Output is correct
23 Correct 72 ms 5196 KB Output is correct
24 Correct 73 ms 5128 KB Output is correct
25 Correct 72 ms 5064 KB Output is correct
26 Correct 72 ms 5068 KB Output is correct
27 Correct 83 ms 5188 KB Output is correct
28 Correct 65 ms 5192 KB Output is correct
29 Correct 64 ms 5392 KB Output is correct
30 Correct 66 ms 5068 KB Output is correct
31 Correct 67 ms 5036 KB Output is correct
32 Correct 110 ms 5184 KB Output is correct
33 Correct 70 ms 5136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 5056 KB Output is correct
2 Correct 69 ms 5040 KB Output is correct
3 Correct 69 ms 5068 KB Output is correct
4 Correct 48 ms 5000 KB Output is correct
5 Correct 44 ms 5108 KB Output is correct
6 Correct 43 ms 5120 KB Output is correct
7 Correct 67 ms 5044 KB Output is correct
8 Correct 84 ms 5184 KB Output is correct
9 Correct 72 ms 5196 KB Output is correct
10 Correct 73 ms 5128 KB Output is correct
11 Correct 72 ms 5064 KB Output is correct
12 Correct 72 ms 5068 KB Output is correct
13 Correct 83 ms 5188 KB Output is correct
14 Correct 65 ms 5192 KB Output is correct
15 Correct 64 ms 5392 KB Output is correct
16 Correct 66 ms 5068 KB Output is correct
17 Correct 67 ms 5036 KB Output is correct
18 Correct 110 ms 5184 KB Output is correct
19 Correct 70 ms 5136 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 0 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 Correct 434 ms 29900 KB Output is correct
35 Correct 427 ms 30104 KB Output is correct
36 Correct 437 ms 30040 KB Output is correct
37 Correct 459 ms 29956 KB Output is correct
38 Correct 496 ms 30140 KB Output is correct
39 Correct 458 ms 30104 KB Output is correct
40 Correct 477 ms 30116 KB Output is correct
41 Correct 481 ms 30028 KB Output is correct
42 Correct 475 ms 30252 KB Output is correct
43 Correct 170 ms 12456 KB Output is correct
44 Correct 160 ms 17964 KB Output is correct
45 Correct 168 ms 18076 KB Output is correct
46 Correct 170 ms 17952 KB Output is correct
47 Correct 436 ms 30268 KB Output is correct
48 Correct 470 ms 30356 KB Output is correct
49 Correct 489 ms 30872 KB Output is correct
50 Correct 413 ms 31932 KB Output is correct
51 Correct 492 ms 31504 KB Output is correct
52 Correct 443 ms 33672 KB Output is correct
53 Correct 445 ms 32328 KB Output is correct
54 Correct 462 ms 29992 KB Output is correct
55 Correct 431 ms 29836 KB Output is correct
56 Correct 430 ms 29892 KB Output is correct
57 Correct 427 ms 30012 KB Output is correct
58 Correct 446 ms 30008 KB Output is correct
59 Correct 428 ms 29936 KB Output is correct
60 Correct 450 ms 29964 KB Output is correct
61 Correct 485 ms 30416 KB Output is correct
62 Correct 476 ms 30276 KB Output is correct
63 Correct 478 ms 30092 KB Output is correct