Submission #401607

# Submission time Handle Problem Language Result Execution time Memory
401607 2021-05-10T14:46:05 Z maximath_1 Peru (RMI20_peru) C++17
100 / 100
163 ms 60148 KB
#include <bits/stdc++.h>
#include "peru.h"
using namespace std;
 
#define ll long long
const ll mod = 1e9 + 7;
const ll base = 23;
const ll inf_ll = mod * 2ll * mod + 69ll;
const int MX = 2500005;
 
ll pwbase[MX];
int n, k, v[MX];
ll dp[MX];
struct dt{
	int id;
	ll dp_id, dp_min;
};
deque<dt> dq;
 
int vv = 0;
void pop_front(){
	if(dq.size()) dq.pop_front();
	if(dq.size()){
		ll dp_i = dq.front().dp_id;
		dq.front().dp_id = inf_ll;
		dq.front().dp_min = inf_ll;
 
		for(int i = 1; i < dq.size(); i ++){
			if(dq[i].dp_id <= dp_i) break;
			vv ++;
			dq[i].dp_min = min(dq[i - 1].dp_min, dq[i].dp_id);
		}
	}
}
 
void push_back(int id){
	if(dq.empty()){
		dq.push_back((dt){id, inf_ll, inf_ll});
		return;
	}
 
	ll bf = dp[dq.back().id];
	dq.push_back((dt){id, bf + v[id], min(bf + v[id], dq.back().dp_min)});
	return;
}
 
int solve(int N, int K, int* V){
	n = N; k = K;
	for(int i = 0; i < n; i ++) v[i] = V[i];
 
	for(int i = 0; i < n; i ++){
		if(dq.size() && i - dq.front().id >= k) pop_front();
		while(dq.size() && v[i] >= v[dq.back().id]) dq.pop_back();
 
		push_back(i);
		dp[i] = (ll)v[dq.front().id];
 
		if(i >= k) dp[i] += dp[i - k];
		if(dq.size())
			dp[i] = min(dp[i], dq.back().dp_min);
	}
 
	assert(vv <= 2 * n);
 
	pwbase[0] = 1ll;
	for(int i = 1; i < n; i ++)
		pwbase[i] = (pwbase[i - 1] * 1ll * base) % mod;
 
	ll ans = 0ll;
 
	for(int i = 0; i < n; i ++){
		dp[i] %= mod;
		(ans += (pwbase[n - 1 - i] * 1ll * dp[i]) % mod) %= mod;
	}
 
	return ans;
}

Compilation message

peru.cpp: In function 'void pop_front()':
peru.cpp:28:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<dt>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |   for(int i = 1; i < dq.size(); i ++){
      |                  ~~^~~~~~~~~~~
# 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 0 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 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 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 0 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 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 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 21 ms 9812 KB Output is correct
16 Correct 21 ms 9788 KB Output is correct
17 Correct 28 ms 9748 KB Output is correct
18 Correct 27 ms 9768 KB Output is correct
19 Correct 27 ms 9732 KB Output is correct
20 Correct 27 ms 9792 KB Output is correct
21 Correct 23 ms 9812 KB Output is correct
22 Correct 22 ms 9836 KB Output is correct
23 Correct 22 ms 9800 KB Output is correct
24 Correct 29 ms 9752 KB Output is correct
25 Correct 24 ms 9812 KB Output is correct
26 Correct 25 ms 9812 KB Output is correct
27 Correct 21 ms 9852 KB Output is correct
28 Correct 21 ms 9812 KB Output is correct
29 Correct 25 ms 9896 KB Output is correct
30 Correct 23 ms 9784 KB Output is correct
31 Correct 25 ms 9804 KB Output is correct
32 Correct 22 ms 9812 KB Output is correct
33 Correct 25 ms 9756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 9812 KB Output is correct
2 Correct 21 ms 9788 KB Output is correct
3 Correct 28 ms 9748 KB Output is correct
4 Correct 27 ms 9768 KB Output is correct
5 Correct 27 ms 9732 KB Output is correct
6 Correct 27 ms 9792 KB Output is correct
7 Correct 23 ms 9812 KB Output is correct
8 Correct 22 ms 9836 KB Output is correct
9 Correct 22 ms 9800 KB Output is correct
10 Correct 29 ms 9752 KB Output is correct
11 Correct 24 ms 9812 KB Output is correct
12 Correct 25 ms 9812 KB Output is correct
13 Correct 21 ms 9852 KB Output is correct
14 Correct 21 ms 9812 KB Output is correct
15 Correct 25 ms 9896 KB Output is correct
16 Correct 23 ms 9784 KB Output is correct
17 Correct 25 ms 9804 KB Output is correct
18 Correct 22 ms 9812 KB Output is correct
19 Correct 25 ms 9756 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 0 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 0 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 0 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 139 ms 59164 KB Output is correct
35 Correct 128 ms 59340 KB Output is correct
36 Correct 139 ms 59264 KB Output is correct
37 Correct 150 ms 59248 KB Output is correct
38 Correct 143 ms 59220 KB Output is correct
39 Correct 143 ms 59248 KB Output is correct
40 Correct 150 ms 59212 KB Output is correct
41 Correct 136 ms 59236 KB Output is correct
42 Correct 132 ms 59288 KB Output is correct
43 Correct 50 ms 23972 KB Output is correct
44 Correct 95 ms 35660 KB Output is correct
45 Correct 100 ms 35732 KB Output is correct
46 Correct 93 ms 35624 KB Output is correct
47 Correct 131 ms 59284 KB Output is correct
48 Correct 131 ms 59348 KB Output is correct
49 Correct 144 ms 59492 KB Output is correct
50 Correct 133 ms 59996 KB Output is correct
51 Correct 129 ms 59788 KB Output is correct
52 Correct 161 ms 60052 KB Output is correct
53 Correct 149 ms 60148 KB Output is correct
54 Correct 161 ms 59236 KB Output is correct
55 Correct 146 ms 59148 KB Output is correct
56 Correct 138 ms 59128 KB Output is correct
57 Correct 136 ms 59160 KB Output is correct
58 Correct 144 ms 59176 KB Output is correct
59 Correct 138 ms 59140 KB Output is correct
60 Correct 144 ms 59240 KB Output is correct
61 Correct 162 ms 59304 KB Output is correct
62 Correct 147 ms 59360 KB Output is correct
63 Correct 163 ms 59320 KB Output is correct