Submission #401636

# Submission time Handle Problem Language Result Execution time Memory
401636 2021-05-10T15:30:39 Z Pyqe Peru (RMI20_peru) C++14
100 / 100
343 ms 229332 KB
#include <bits/stdc++.h>
#include "peru.h"

using namespace std;

#define mp make_pair
#define fr first
#define sc second

const int m=23,dv=1e9+7;
const long long inf=1e18;
int d,nn=0,a[2500069],sk[2500069],fh[2500069],sr[2500069];
long long dp[2500069];
vector<int> al[2500069];
deque<pair<int,long long>> dq;
bitset<2500069> spc;

void bd(int x)
{
	int i,sz=al[x].size(),l;
	
	fh[x]=x;
	for(i=0;i<sz;i++)
	{
		l=al[x][i];
		bd(l);
		fh[x]=max(fh[x],fh[l]);
	}
}

void dfs(int x,long long cw)
{
	int i,sz=al[x].size(),l;
	
	dp[x]=min(cw,dp[max(x-d,0)]+a[sr[x]]);
	for(;!dq.empty()&&dq.front().fr<x-d;dq.pop_front());
	if(!dq.empty())
	{
		dp[x]=min(dp[x],dq.front().sc);
	}
	for(i=0;i<sz;i++)
	{
		l=al[x][i];
		if(fh[l]-d>x)
		{
			for(;!dq.empty()&&dq.back().sc>=dp[x]+a[l];dq.pop_back());
			dq.push_back({x,dp[x]+a[l]});
			dfs(l,cw);
		}
		else
		{
			dfs(l,min(cw,dp[x]+a[l]));
		}
	}
}

int solve(int n,int od,int* aa)
{
	int i,j,ml=1,z=0;
	
	d=od;
	for(j=0,i=1;i<=n;i++)
	{
		a[i]=aa[i-1];
		for(;nn&&a[sk[nn]]<=a[i];nn--)
		{
			spc[sk[nn]]=0;
		}
		al[sk[nn]].push_back(i);
		nn++;
		sk[nn]=i;
		spc[i]=1;
		for(;j<=i-d||!spc[j];j++);
		sr[i]=j;
	}
	bd(0);
	dfs(0,inf);
	for(i=n;i;i--)
	{
		z=(z+dp[i]%dv*ml)%dv;
		ml=(long long)ml*m%dv;
	}
	return z;
}
# Verdict Execution time Memory Grader output
1 Correct 28 ms 59108 KB Output is correct
2 Correct 28 ms 59220 KB Output is correct
3 Correct 33 ms 59116 KB Output is correct
4 Correct 30 ms 59172 KB Output is correct
5 Correct 30 ms 59104 KB Output is correct
6 Correct 29 ms 59156 KB Output is correct
7 Correct 34 ms 59220 KB Output is correct
8 Correct 29 ms 59236 KB Output is correct
9 Correct 29 ms 59220 KB Output is correct
10 Correct 28 ms 59140 KB Output is correct
11 Correct 37 ms 59144 KB Output is correct
12 Correct 28 ms 59092 KB Output is correct
13 Correct 28 ms 59092 KB Output is correct
14 Correct 35 ms 59120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 59108 KB Output is correct
2 Correct 28 ms 59220 KB Output is correct
3 Correct 33 ms 59116 KB Output is correct
4 Correct 30 ms 59172 KB Output is correct
5 Correct 30 ms 59104 KB Output is correct
6 Correct 29 ms 59156 KB Output is correct
7 Correct 34 ms 59220 KB Output is correct
8 Correct 29 ms 59236 KB Output is correct
9 Correct 29 ms 59220 KB Output is correct
10 Correct 28 ms 59140 KB Output is correct
11 Correct 37 ms 59144 KB Output is correct
12 Correct 28 ms 59092 KB Output is correct
13 Correct 28 ms 59092 KB Output is correct
14 Correct 35 ms 59120 KB Output is correct
15 Correct 71 ms 81556 KB Output is correct
16 Correct 116 ms 81992 KB Output is correct
17 Correct 77 ms 83020 KB Output is correct
18 Correct 84 ms 75104 KB Output is correct
19 Correct 75 ms 75112 KB Output is correct
20 Correct 78 ms 74992 KB Output is correct
21 Correct 76 ms 82004 KB Output is correct
22 Correct 80 ms 84220 KB Output is correct
23 Correct 82 ms 84132 KB Output is correct
24 Correct 86 ms 82636 KB Output is correct
25 Correct 71 ms 85176 KB Output is correct
26 Correct 76 ms 81664 KB Output is correct
27 Correct 69 ms 81848 KB Output is correct
28 Correct 74 ms 82616 KB Output is correct
29 Correct 69 ms 81772 KB Output is correct
30 Correct 73 ms 81916 KB Output is correct
31 Correct 71 ms 81808 KB Output is correct
32 Correct 80 ms 82696 KB Output is correct
33 Correct 70 ms 82196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 71 ms 81556 KB Output is correct
2 Correct 116 ms 81992 KB Output is correct
3 Correct 77 ms 83020 KB Output is correct
4 Correct 84 ms 75104 KB Output is correct
5 Correct 75 ms 75112 KB Output is correct
6 Correct 78 ms 74992 KB Output is correct
7 Correct 76 ms 82004 KB Output is correct
8 Correct 80 ms 84220 KB Output is correct
9 Correct 82 ms 84132 KB Output is correct
10 Correct 86 ms 82636 KB Output is correct
11 Correct 71 ms 85176 KB Output is correct
12 Correct 76 ms 81664 KB Output is correct
13 Correct 69 ms 81848 KB Output is correct
14 Correct 74 ms 82616 KB Output is correct
15 Correct 69 ms 81772 KB Output is correct
16 Correct 73 ms 81916 KB Output is correct
17 Correct 71 ms 81808 KB Output is correct
18 Correct 80 ms 82696 KB Output is correct
19 Correct 70 ms 82196 KB Output is correct
20 Correct 28 ms 59108 KB Output is correct
21 Correct 28 ms 59220 KB Output is correct
22 Correct 33 ms 59116 KB Output is correct
23 Correct 30 ms 59172 KB Output is correct
24 Correct 30 ms 59104 KB Output is correct
25 Correct 29 ms 59156 KB Output is correct
26 Correct 34 ms 59220 KB Output is correct
27 Correct 29 ms 59236 KB Output is correct
28 Correct 29 ms 59220 KB Output is correct
29 Correct 28 ms 59140 KB Output is correct
30 Correct 37 ms 59144 KB Output is correct
31 Correct 28 ms 59092 KB Output is correct
32 Correct 28 ms 59092 KB Output is correct
33 Correct 35 ms 59120 KB Output is correct
34 Correct 293 ms 201092 KB Output is correct
35 Correct 319 ms 205480 KB Output is correct
36 Correct 288 ms 199728 KB Output is correct
37 Correct 293 ms 201868 KB Output is correct
38 Correct 300 ms 200608 KB Output is correct
39 Correct 289 ms 203652 KB Output is correct
40 Correct 318 ms 211596 KB Output is correct
41 Correct 301 ms 208204 KB Output is correct
42 Correct 288 ms 207216 KB Output is correct
43 Correct 147 ms 115940 KB Output is correct
44 Correct 220 ms 118900 KB Output is correct
45 Correct 212 ms 118916 KB Output is correct
46 Correct 235 ms 118852 KB Output is correct
47 Correct 304 ms 205892 KB Output is correct
48 Correct 290 ms 210660 KB Output is correct
49 Correct 339 ms 208716 KB Output is correct
50 Correct 267 ms 201740 KB Output is correct
51 Correct 308 ms 206284 KB Output is correct
52 Correct 287 ms 207748 KB Output is correct
53 Correct 328 ms 201800 KB Output is correct
54 Correct 343 ms 198896 KB Output is correct
55 Correct 281 ms 195532 KB Output is correct
56 Correct 313 ms 195704 KB Output is correct
57 Correct 313 ms 195828 KB Output is correct
58 Correct 302 ms 200584 KB Output is correct
59 Correct 309 ms 204424 KB Output is correct
60 Correct 314 ms 201028 KB Output is correct
61 Correct 334 ms 229332 KB Output is correct
62 Correct 320 ms 219548 KB Output is correct
63 Correct 324 ms 211360 KB Output is correct