Submission #746318

# Submission time Handle Problem Language Result Execution time Memory
746318 2023-05-22T10:39:40 Z doowey Peru (RMI20_peru) C++14
0 / 100
1 ms 340 KB
#include <bits/stdc++.h>
#include "peru.h"

using namespace std;

typedef long long ll;
typedef pair<ll, int> pii;

#define fi first
#define se second
#define mp make_pair

const int N = 2511111;
const int MOD = (int)1e9 + 7;
ll dp[N];
ll A[N];
bool off[N];

int solve(int n, int k, int* v){
    A[0] = (ll)1e18;
    for(int i = 1; i <= n; i ++ ){
        A[i] = v[i - 1];
    }
    deque<int> big;
    big.push_back(0);
    priority_queue<pii, vector<pii>, greater<pii>> pq;
    for(int i = 1; i <= n; i ++ ){
        while(!big.empty() && A[big.back()] <= A[i]){
            big.pop_back();
            off[big.back() + 1] = true;
        }
        if(!big.empty()){
            pq.push(mp(A[i] + dp[big.back()], big.back() + 1));
            off[big.back() + 1] = false;
            //cout << A[i] + dp[big.back()] << " " << big.back() + 1 << "\n";
        }
        big.push_back(i);
        while(big.front() <= i - k){
            big.pop_front();
        }
        while(!pq.empty() && (off[pq.top().se] || pq.top().se <= i - k)) pq.pop();
        dp[i] = (ll)1e9;
        if(!pq.empty())
            dp[i] = min(dp[i], pq.top().fi);
        dp[i] = min(dp[i], A[big.front()] + dp[max(0, i - k)]);
    }
    int p = 1;
    int chum = 0;
    for(int i = n; i >= 1; i -- ){
        chum += (p * 1ll * dp[i]) % MOD;
        if(chum >= MOD) chum -= MOD;
        p = (p * 23ll) % MOD;
    }
    return chum;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -