# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1065955 |
2024-08-19T13:30:29 Z |
Rafi22 |
Peru (RMI20_peru) |
C++14 |
|
600 ms |
164808 KB |
#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];
vector<pair<int,int>>G[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;
vector<pair<int,int>>X;
X.pb({inf,0});
FOR(i,1,n+1)
{
int last=-1;
while(X.back().st<a[i])
{
if(last!=-1&&i-1-X.back().nd<=k) G[i-1].pb({X.back().nd,last});
last=X.back().st;
X.pop_back();
}
if(last!=-1&&i-1-X.back().nd<=k) G[i-1].pb({X.back().nd,last});
X.pb({a[i],i});
}
X.clear();
X.pb({inf,n+1});
ROF(i,n,0)
{
int last=-1;
while(X.back().st<a[i])
{
if(last!=-1&&X.back().nd-1-i<=k) G[X.back().nd-1].pb({i,last});
last=X.back().st;
X.pop_back();
}
if(last!=-1&&X.back().nd-1-i<=k) G[X.back().nd-1].pb({i,last});
X.pb({a[i],i});
}
deque<pair<ll,int>>Q;
FOR(i,1,n)
{
DP[i]=infl;
if(sz(Q)>0&&Q[0].nd<=i-k) Q.pop_front();
while(sz(Q)>0&&Q.back().st<a[i]) Q.pop_back();
Q.pb({a[i],i});
DP[i]=DP[max(0,i-k)]+Q[0].st;
for(auto [j,c]:G[i])
{
debug(i,j,c);
DP[i]=min(DP[i],DP[j]+c);
}
ROF(j,i-1,1)
{
if(DP[j]<=DP[i]) break;
DP[j]=DP[i];
}
}
/*FOR(i,1,n)
{
DP1[i]=infl;
int mx=0;
ROF(j,i,1)
{
if(i-j+1>k) break;
mx=max(mx,a[j]);
DP1[i]=min(DP1[i],DP1[j-1]+mx);
}
}
FOR(i,1,n) debug(DP[i],DP1[i]);*/
ll h=0,pot=1;
ROF(i,n,1)
{
h=(h+DP[i]%mod*pot)%mod;
pot=pot*23%mod;
}
return (int)h;
}
Compilation message
peru.cpp: In function 'int solve(int, int, int*)':
peru.cpp:77:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
77 | for(auto [j,c]:G[i])
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
59228 KB |
Output is correct |
2 |
Correct |
28 ms |
59224 KB |
Output is correct |
3 |
Correct |
27 ms |
59228 KB |
Output is correct |
4 |
Correct |
27 ms |
59164 KB |
Output is correct |
5 |
Correct |
25 ms |
59072 KB |
Output is correct |
6 |
Correct |
27 ms |
59228 KB |
Output is correct |
7 |
Correct |
28 ms |
59228 KB |
Output is correct |
8 |
Correct |
32 ms |
59228 KB |
Output is correct |
9 |
Correct |
26 ms |
59228 KB |
Output is correct |
10 |
Correct |
28 ms |
59228 KB |
Output is correct |
11 |
Correct |
27 ms |
59228 KB |
Output is correct |
12 |
Correct |
28 ms |
59168 KB |
Output is correct |
13 |
Correct |
26 ms |
59232 KB |
Output is correct |
14 |
Correct |
28 ms |
59124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
59228 KB |
Output is correct |
2 |
Correct |
28 ms |
59224 KB |
Output is correct |
3 |
Correct |
27 ms |
59228 KB |
Output is correct |
4 |
Correct |
27 ms |
59164 KB |
Output is correct |
5 |
Correct |
25 ms |
59072 KB |
Output is correct |
6 |
Correct |
27 ms |
59228 KB |
Output is correct |
7 |
Correct |
28 ms |
59228 KB |
Output is correct |
8 |
Correct |
32 ms |
59228 KB |
Output is correct |
9 |
Correct |
26 ms |
59228 KB |
Output is correct |
10 |
Correct |
28 ms |
59228 KB |
Output is correct |
11 |
Correct |
27 ms |
59228 KB |
Output is correct |
12 |
Correct |
28 ms |
59168 KB |
Output is correct |
13 |
Correct |
26 ms |
59232 KB |
Output is correct |
14 |
Correct |
28 ms |
59124 KB |
Output is correct |
15 |
Correct |
65 ms |
76480 KB |
Output is correct |
16 |
Correct |
70 ms |
76368 KB |
Output is correct |
17 |
Correct |
67 ms |
73932 KB |
Output is correct |
18 |
Correct |
80 ms |
78872 KB |
Output is correct |
19 |
Correct |
85 ms |
80212 KB |
Output is correct |
20 |
Correct |
86 ms |
79916 KB |
Output is correct |
21 |
Correct |
64 ms |
76368 KB |
Output is correct |
22 |
Correct |
80 ms |
75244 KB |
Output is correct |
23 |
Correct |
87 ms |
75468 KB |
Output is correct |
24 |
Correct |
74 ms |
73080 KB |
Output is correct |
25 |
Correct |
76 ms |
73412 KB |
Output is correct |
26 |
Correct |
62 ms |
76372 KB |
Output is correct |
27 |
Correct |
68 ms |
77564 KB |
Output is correct |
28 |
Correct |
62 ms |
77700 KB |
Output is correct |
29 |
Correct |
60 ms |
77904 KB |
Output is correct |
30 |
Correct |
71 ms |
76368 KB |
Output is correct |
31 |
Correct |
64 ms |
74928 KB |
Output is correct |
32 |
Correct |
66 ms |
77392 KB |
Output is correct |
33 |
Correct |
58 ms |
74896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
76480 KB |
Output is correct |
2 |
Correct |
70 ms |
76368 KB |
Output is correct |
3 |
Correct |
67 ms |
73932 KB |
Output is correct |
4 |
Correct |
80 ms |
78872 KB |
Output is correct |
5 |
Correct |
85 ms |
80212 KB |
Output is correct |
6 |
Correct |
86 ms |
79916 KB |
Output is correct |
7 |
Correct |
64 ms |
76368 KB |
Output is correct |
8 |
Correct |
80 ms |
75244 KB |
Output is correct |
9 |
Correct |
87 ms |
75468 KB |
Output is correct |
10 |
Correct |
74 ms |
73080 KB |
Output is correct |
11 |
Correct |
76 ms |
73412 KB |
Output is correct |
12 |
Correct |
62 ms |
76372 KB |
Output is correct |
13 |
Correct |
68 ms |
77564 KB |
Output is correct |
14 |
Correct |
62 ms |
77700 KB |
Output is correct |
15 |
Correct |
60 ms |
77904 KB |
Output is correct |
16 |
Correct |
71 ms |
76368 KB |
Output is correct |
17 |
Correct |
64 ms |
74928 KB |
Output is correct |
18 |
Correct |
66 ms |
77392 KB |
Output is correct |
19 |
Correct |
58 ms |
74896 KB |
Output is correct |
20 |
Correct |
29 ms |
59228 KB |
Output is correct |
21 |
Correct |
28 ms |
59224 KB |
Output is correct |
22 |
Correct |
27 ms |
59228 KB |
Output is correct |
23 |
Correct |
27 ms |
59164 KB |
Output is correct |
24 |
Correct |
25 ms |
59072 KB |
Output is correct |
25 |
Correct |
27 ms |
59228 KB |
Output is correct |
26 |
Correct |
28 ms |
59228 KB |
Output is correct |
27 |
Correct |
32 ms |
59228 KB |
Output is correct |
28 |
Correct |
26 ms |
59228 KB |
Output is correct |
29 |
Correct |
28 ms |
59228 KB |
Output is correct |
30 |
Correct |
27 ms |
59228 KB |
Output is correct |
31 |
Correct |
28 ms |
59168 KB |
Output is correct |
32 |
Correct |
26 ms |
59232 KB |
Output is correct |
33 |
Correct |
28 ms |
59124 KB |
Output is correct |
34 |
Correct |
309 ms |
157172 KB |
Output is correct |
35 |
Correct |
371 ms |
164808 KB |
Output is correct |
36 |
Correct |
342 ms |
163812 KB |
Output is correct |
37 |
Correct |
480 ms |
157132 KB |
Output is correct |
38 |
Correct |
416 ms |
160372 KB |
Output is correct |
39 |
Correct |
562 ms |
161324 KB |
Output is correct |
40 |
Execution timed out |
838 ms |
151652 KB |
Time limit exceeded |
41 |
Halted |
0 ms |
0 KB |
- |