#include "peru.h"
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
auto&operator<<(auto&o,pair<auto,auto>p){return o<<"("<<p.first<<", "<<p.second<<")";}
auto operator<<(auto&o,auto x)->decltype(x.end(),o){o<<"{";int i=0;for(auto e:x)o<<","+!i++<<e;return o<<"}";}
#define debug(X...)cerr<<"["#X"]: ",[](auto...$){((cerr<<$<<"; "),...)<<endl;}(X)
#else
#define debug(...){}
#endif
#define ll long long
#define ld long double
#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define FOR(i,l,r) for(int i=(l);i<=(r);i++)
#define ROF(i,r,l) for(int i=(r);i>=(l);i--)
int inf=2000000007;
ll infl=1000000000000000007;
ll mod=1000000007;
ll mod1=998244353;
const int N=2500007;
//ll DP1[N];
ll DP[N];
int a[N];
int solve(int n,int k,int* v)
{
FOR(i,1,n) a[i]=v[i-1];
a[0]=inf,a[n+1]=inf;
deque<pair<int,int>>X;
X.pb({inf,0});
FOR(i,1,n+1)
{
int last=-1;
while(sz(X)>0&&X.back().st<a[i])
{
if(sz(X)>0&&last!=-1&&i-1-X.back().nd<=k) DP[i-1]=min(DP[i-1],DP[X.back().nd]+last);
last=X.back().st;
X.pop_back();
}
if(sz(X)>0&&last!=-1&&i-1-X.back().nd<=k) DP[i-1]=min(DP[i-1],DP[X.back().nd]+last);
ROF(j,i-2,1)
{
if(DP[j]<=DP[i-1]) break;
DP[j]=DP[i-1];
}
if(sz(X)>0&&X[0].nd<=i-k) X.pop_front();
X.pb({a[i],i});
if(i==n+1) break;
DP[i]=infl;
if(sz(X)>0) DP[i]=DP[max(0,i-k)]+X[0].st;
}
ll h=0;
FOR(i,1,n) h=(23*h+DP[i])%mod;
return (int)h;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
468 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
472 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
468 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
472 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
22 ms |
10716 KB |
Output is correct |
16 |
Correct |
22 ms |
10836 KB |
Output is correct |
17 |
Correct |
24 ms |
10832 KB |
Output is correct |
18 |
Correct |
24 ms |
10832 KB |
Output is correct |
19 |
Correct |
19 ms |
10836 KB |
Output is correct |
20 |
Correct |
19 ms |
10832 KB |
Output is correct |
21 |
Correct |
21 ms |
10832 KB |
Output is correct |
22 |
Correct |
41 ms |
10836 KB |
Output is correct |
23 |
Correct |
50 ms |
10764 KB |
Output is correct |
24 |
Correct |
41 ms |
10752 KB |
Output is correct |
25 |
Correct |
43 ms |
10708 KB |
Output is correct |
26 |
Correct |
19 ms |
10844 KB |
Output is correct |
27 |
Correct |
19 ms |
10772 KB |
Output is correct |
28 |
Correct |
20 ms |
10832 KB |
Output is correct |
29 |
Correct |
18 ms |
10836 KB |
Output is correct |
30 |
Correct |
26 ms |
10780 KB |
Output is correct |
31 |
Correct |
21 ms |
10832 KB |
Output is correct |
32 |
Correct |
24 ms |
10788 KB |
Output is correct |
33 |
Correct |
21 ms |
10856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
10716 KB |
Output is correct |
2 |
Correct |
22 ms |
10836 KB |
Output is correct |
3 |
Correct |
24 ms |
10832 KB |
Output is correct |
4 |
Correct |
24 ms |
10832 KB |
Output is correct |
5 |
Correct |
19 ms |
10836 KB |
Output is correct |
6 |
Correct |
19 ms |
10832 KB |
Output is correct |
7 |
Correct |
21 ms |
10832 KB |
Output is correct |
8 |
Correct |
41 ms |
10836 KB |
Output is correct |
9 |
Correct |
50 ms |
10764 KB |
Output is correct |
10 |
Correct |
41 ms |
10752 KB |
Output is correct |
11 |
Correct |
43 ms |
10708 KB |
Output is correct |
12 |
Correct |
19 ms |
10844 KB |
Output is correct |
13 |
Correct |
19 ms |
10772 KB |
Output is correct |
14 |
Correct |
20 ms |
10832 KB |
Output is correct |
15 |
Correct |
18 ms |
10836 KB |
Output is correct |
16 |
Correct |
26 ms |
10780 KB |
Output is correct |
17 |
Correct |
21 ms |
10832 KB |
Output is correct |
18 |
Correct |
24 ms |
10788 KB |
Output is correct |
19 |
Correct |
21 ms |
10856 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
468 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
472 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
213 ms |
62996 KB |
Output is correct |
35 |
Correct |
277 ms |
63056 KB |
Output is correct |
36 |
Correct |
250 ms |
63176 KB |
Output is correct |
37 |
Correct |
426 ms |
63296 KB |
Output is correct |
38 |
Correct |
340 ms |
63132 KB |
Output is correct |
39 |
Correct |
520 ms |
63148 KB |
Output is correct |
40 |
Execution timed out |
859 ms |
63176 KB |
Time limit exceeded |
41 |
Halted |
0 ms |
0 KB |
- |