# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
401628 |
2021-05-10T15:07:39 Z |
Pyqe |
Peru (RMI20_peru) |
C++14 |
|
372 ms |
262144 KB |
#include <bits/stdc++.h>
#include "peru.h"
using namespace std;
#define mp make_pair
#define fr first
#define sc second
const long long m=23,dv=1e9+7,inf=1e18;
long long d,nn=0,a[2500069],dp[2500069],sk[2500069],fh[2500069],sr[2500069];
vector<long long> al[2500069];
deque<pair<long long,long long>> dq;
bitset<2500069> spc;
void bd(long long x)
{
long long 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(long long x,long long cw)
{
long long i,sz=al[x].size(),l;
dp[x]=min(cw,dp[max(x-d,0ll)]+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)
{
long long 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=ml*m%dv;
}
return z;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
59156 KB |
Output is correct |
2 |
Correct |
29 ms |
59300 KB |
Output is correct |
3 |
Correct |
34 ms |
59160 KB |
Output is correct |
4 |
Correct |
35 ms |
59104 KB |
Output is correct |
5 |
Correct |
35 ms |
59180 KB |
Output is correct |
6 |
Correct |
28 ms |
59136 KB |
Output is correct |
7 |
Correct |
31 ms |
59188 KB |
Output is correct |
8 |
Correct |
29 ms |
59268 KB |
Output is correct |
9 |
Correct |
34 ms |
59204 KB |
Output is correct |
10 |
Correct |
30 ms |
59120 KB |
Output is correct |
11 |
Correct |
32 ms |
59108 KB |
Output is correct |
12 |
Correct |
30 ms |
59072 KB |
Output is correct |
13 |
Correct |
35 ms |
59084 KB |
Output is correct |
14 |
Correct |
31 ms |
59096 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
59156 KB |
Output is correct |
2 |
Correct |
29 ms |
59300 KB |
Output is correct |
3 |
Correct |
34 ms |
59160 KB |
Output is correct |
4 |
Correct |
35 ms |
59104 KB |
Output is correct |
5 |
Correct |
35 ms |
59180 KB |
Output is correct |
6 |
Correct |
28 ms |
59136 KB |
Output is correct |
7 |
Correct |
31 ms |
59188 KB |
Output is correct |
8 |
Correct |
29 ms |
59268 KB |
Output is correct |
9 |
Correct |
34 ms |
59204 KB |
Output is correct |
10 |
Correct |
30 ms |
59120 KB |
Output is correct |
11 |
Correct |
32 ms |
59108 KB |
Output is correct |
12 |
Correct |
30 ms |
59072 KB |
Output is correct |
13 |
Correct |
35 ms |
59084 KB |
Output is correct |
14 |
Correct |
31 ms |
59096 KB |
Output is correct |
15 |
Correct |
76 ms |
86424 KB |
Output is correct |
16 |
Correct |
79 ms |
86924 KB |
Output is correct |
17 |
Correct |
89 ms |
88040 KB |
Output is correct |
18 |
Correct |
88 ms |
80768 KB |
Output is correct |
19 |
Correct |
82 ms |
80736 KB |
Output is correct |
20 |
Correct |
84 ms |
80768 KB |
Output is correct |
21 |
Correct |
79 ms |
86772 KB |
Output is correct |
22 |
Correct |
74 ms |
89412 KB |
Output is correct |
23 |
Correct |
81 ms |
89400 KB |
Output is correct |
24 |
Correct |
79 ms |
87732 KB |
Output is correct |
25 |
Correct |
83 ms |
90608 KB |
Output is correct |
26 |
Correct |
81 ms |
86480 KB |
Output is correct |
27 |
Correct |
73 ms |
86732 KB |
Output is correct |
28 |
Correct |
81 ms |
87400 KB |
Output is correct |
29 |
Correct |
72 ms |
86680 KB |
Output is correct |
30 |
Correct |
74 ms |
86824 KB |
Output is correct |
31 |
Correct |
75 ms |
86528 KB |
Output is correct |
32 |
Correct |
71 ms |
87684 KB |
Output is correct |
33 |
Correct |
72 ms |
86984 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
76 ms |
86424 KB |
Output is correct |
2 |
Correct |
79 ms |
86924 KB |
Output is correct |
3 |
Correct |
89 ms |
88040 KB |
Output is correct |
4 |
Correct |
88 ms |
80768 KB |
Output is correct |
5 |
Correct |
82 ms |
80736 KB |
Output is correct |
6 |
Correct |
84 ms |
80768 KB |
Output is correct |
7 |
Correct |
79 ms |
86772 KB |
Output is correct |
8 |
Correct |
74 ms |
89412 KB |
Output is correct |
9 |
Correct |
81 ms |
89400 KB |
Output is correct |
10 |
Correct |
79 ms |
87732 KB |
Output is correct |
11 |
Correct |
83 ms |
90608 KB |
Output is correct |
12 |
Correct |
81 ms |
86480 KB |
Output is correct |
13 |
Correct |
73 ms |
86732 KB |
Output is correct |
14 |
Correct |
81 ms |
87400 KB |
Output is correct |
15 |
Correct |
72 ms |
86680 KB |
Output is correct |
16 |
Correct |
74 ms |
86824 KB |
Output is correct |
17 |
Correct |
75 ms |
86528 KB |
Output is correct |
18 |
Correct |
71 ms |
87684 KB |
Output is correct |
19 |
Correct |
72 ms |
86984 KB |
Output is correct |
20 |
Correct |
37 ms |
59156 KB |
Output is correct |
21 |
Correct |
29 ms |
59300 KB |
Output is correct |
22 |
Correct |
34 ms |
59160 KB |
Output is correct |
23 |
Correct |
35 ms |
59104 KB |
Output is correct |
24 |
Correct |
35 ms |
59180 KB |
Output is correct |
25 |
Correct |
28 ms |
59136 KB |
Output is correct |
26 |
Correct |
31 ms |
59188 KB |
Output is correct |
27 |
Correct |
29 ms |
59268 KB |
Output is correct |
28 |
Correct |
34 ms |
59204 KB |
Output is correct |
29 |
Correct |
30 ms |
59120 KB |
Output is correct |
30 |
Correct |
32 ms |
59108 KB |
Output is correct |
31 |
Correct |
30 ms |
59072 KB |
Output is correct |
32 |
Correct |
35 ms |
59084 KB |
Output is correct |
33 |
Correct |
31 ms |
59096 KB |
Output is correct |
34 |
Correct |
294 ms |
231604 KB |
Output is correct |
35 |
Correct |
331 ms |
236512 KB |
Output is correct |
36 |
Correct |
296 ms |
229856 KB |
Output is correct |
37 |
Correct |
323 ms |
232380 KB |
Output is correct |
38 |
Correct |
306 ms |
230724 KB |
Output is correct |
39 |
Correct |
330 ms |
234464 KB |
Output is correct |
40 |
Correct |
353 ms |
243704 KB |
Output is correct |
41 |
Correct |
328 ms |
239684 KB |
Output is correct |
42 |
Correct |
372 ms |
238724 KB |
Output is correct |
43 |
Correct |
142 ms |
128012 KB |
Output is correct |
44 |
Correct |
236 ms |
140272 KB |
Output is correct |
45 |
Correct |
241 ms |
140332 KB |
Output is correct |
46 |
Correct |
228 ms |
140236 KB |
Output is correct |
47 |
Correct |
346 ms |
237012 KB |
Output is correct |
48 |
Correct |
324 ms |
242640 KB |
Output is correct |
49 |
Correct |
328 ms |
240208 KB |
Output is correct |
50 |
Correct |
304 ms |
232060 KB |
Output is correct |
51 |
Correct |
324 ms |
237520 KB |
Output is correct |
52 |
Correct |
304 ms |
239224 KB |
Output is correct |
53 |
Correct |
328 ms |
232164 KB |
Output is correct |
54 |
Correct |
321 ms |
228840 KB |
Output is correct |
55 |
Correct |
286 ms |
224976 KB |
Output is correct |
56 |
Correct |
300 ms |
224972 KB |
Output is correct |
57 |
Correct |
283 ms |
225100 KB |
Output is correct |
58 |
Correct |
299 ms |
230712 KB |
Output is correct |
59 |
Correct |
303 ms |
234892 KB |
Output is correct |
60 |
Correct |
300 ms |
230628 KB |
Output is correct |
61 |
Runtime error |
322 ms |
262144 KB |
Execution killed with signal 9 |
62 |
Halted |
0 ms |
0 KB |
- |