Submission #850528

# Submission time Handle Problem Language Result Execution time Memory
850528 2023-09-16T19:45:15 Z alexdd Peru (RMI20_peru) C++17
49 / 100
600 ms 72528 KB
#include "peru.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9+7;

set<pair<ll,int>> s;
void adauga(pair<ll,int> x)
{
    s.insert(x);
}
void sterge(pair<ll,int> x)
{
    s.erase(x);
}
pair<ll,int> getmin()
{
    auto it = s.begin();
    return *it;
}

ll dp[2500005];
int put23[2500005];
int a[2500005];
int solve(int n, int k, int* v)
{
    dp[0]=0;
    deque<pair<int,int>> dq;
    dq.push_back({0,0});
    a[0]=0;
    adauga({0,0});
    ll rez = 0;
    put23[0]=1;
    for(int i=1;i<=n;i++)
        put23[i]=(put23[i-1]*23LL)%MOD;
    for(int i=1;i<=n;i++)
    {
        a[i]=v[i-1];
        if(!dq.empty() && i-dq.front().first>k)
        {
            pair<int,int> x = dq.front();
            sterge({dp[dq.front().first]+dq.front().second, dq.front().first});
            dq.pop_front();
            if(dq.empty() || dq.front().first > x.first+1)
            {
                dq.push_front({x.first+1,x.second});
                adauga({dp[x.first+1]+x.second, x.first+1});
            }
        }
        dp[i]=INF;
        int ult=-1;
        while(!dq.empty() && dq.back().second<a[i])
        {
            ult=dq.back().first;
            sterge({dp[dq.back().first]+dq.back().second, dq.back().first});
            dq.pop_back();
        }
        if(ult!=-1 && (dq.empty() || dq.back().second>a[i]))
        {
            dq.push_back({ult,a[i]});
            adauga({dp[ult]+a[i],ult});
        }

        /*cout<<i<<"\n";
        for(int j=0;j<dq.size();j++)
            cout<<dq[j].first<<" "<<dq[j].second<<"\n";
        cout<<"\n\n";*/
        dp[i] = getmin().first;
        dq.push_back({i,0});
        adauga({dp[i]+0,i});
        //cout<<i<<" "<<dp[i]<<" zzz\n";
        rez = (rez + ((dp[i]%MOD)*put23[n-i])%MOD)%MOD;
    }
    return rez;
}
/**

dp[i] = min(dp[j] + max(j+1..i))

*/
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6488 KB Output is correct
2 Correct 2 ms 6488 KB Output is correct
3 Correct 2 ms 6652 KB Output is correct
4 Correct 1 ms 6692 KB Output is correct
5 Correct 1 ms 6488 KB Output is correct
6 Correct 1 ms 6488 KB Output is correct
7 Correct 2 ms 6488 KB Output is correct
8 Correct 1 ms 6488 KB Output is correct
9 Correct 2 ms 6488 KB Output is correct
10 Correct 2 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6488 KB Output is correct
14 Correct 2 ms 6488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6488 KB Output is correct
2 Correct 2 ms 6488 KB Output is correct
3 Correct 2 ms 6652 KB Output is correct
4 Correct 1 ms 6692 KB Output is correct
5 Correct 1 ms 6488 KB Output is correct
6 Correct 1 ms 6488 KB Output is correct
7 Correct 2 ms 6488 KB Output is correct
8 Correct 1 ms 6488 KB Output is correct
9 Correct 2 ms 6488 KB Output is correct
10 Correct 2 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6488 KB Output is correct
14 Correct 2 ms 6488 KB Output is correct
15 Correct 121 ms 19372 KB Output is correct
16 Correct 128 ms 19024 KB Output is correct
17 Correct 116 ms 18980 KB Output is correct
18 Correct 93 ms 19280 KB Output is correct
19 Correct 91 ms 19116 KB Output is correct
20 Correct 90 ms 19164 KB Output is correct
21 Correct 121 ms 19024 KB Output is correct
22 Correct 121 ms 19284 KB Output is correct
23 Correct 122 ms 19280 KB Output is correct
24 Correct 113 ms 19096 KB Output is correct
25 Correct 117 ms 19280 KB Output is correct
26 Correct 117 ms 19200 KB Output is correct
27 Correct 122 ms 19024 KB Output is correct
28 Correct 119 ms 19280 KB Output is correct
29 Correct 115 ms 19536 KB Output is correct
30 Correct 124 ms 19228 KB Output is correct
31 Correct 114 ms 19024 KB Output is correct
32 Correct 123 ms 19368 KB Output is correct
33 Correct 113 ms 19024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 121 ms 19372 KB Output is correct
2 Correct 128 ms 19024 KB Output is correct
3 Correct 116 ms 18980 KB Output is correct
4 Correct 93 ms 19280 KB Output is correct
5 Correct 91 ms 19116 KB Output is correct
6 Correct 90 ms 19164 KB Output is correct
7 Correct 121 ms 19024 KB Output is correct
8 Correct 121 ms 19284 KB Output is correct
9 Correct 122 ms 19280 KB Output is correct
10 Correct 113 ms 19096 KB Output is correct
11 Correct 117 ms 19280 KB Output is correct
12 Correct 117 ms 19200 KB Output is correct
13 Correct 122 ms 19024 KB Output is correct
14 Correct 119 ms 19280 KB Output is correct
15 Correct 115 ms 19536 KB Output is correct
16 Correct 124 ms 19228 KB Output is correct
17 Correct 114 ms 19024 KB Output is correct
18 Correct 123 ms 19368 KB Output is correct
19 Correct 113 ms 19024 KB Output is correct
20 Correct 2 ms 6488 KB Output is correct
21 Correct 2 ms 6488 KB Output is correct
22 Correct 2 ms 6652 KB Output is correct
23 Correct 1 ms 6692 KB Output is correct
24 Correct 1 ms 6488 KB Output is correct
25 Correct 1 ms 6488 KB Output is correct
26 Correct 2 ms 6488 KB Output is correct
27 Correct 1 ms 6488 KB Output is correct
28 Correct 2 ms 6488 KB Output is correct
29 Correct 2 ms 6492 KB Output is correct
30 Correct 1 ms 6492 KB Output is correct
31 Correct 1 ms 6492 KB Output is correct
32 Correct 1 ms 6488 KB Output is correct
33 Correct 2 ms 6488 KB Output is correct
34 Execution timed out 748 ms 72528 KB Time limit exceeded
35 Halted 0 ms 0 KB -