Submission #1061755

# Submission time Handle Problem Language Result Execution time Memory
1061755 2024-08-16T12:42:19 Z TimDee Peru (RMI20_peru) C++17
0 / 100
0 ms 348 KB
#include "peru.h"
#include <bits/stdc++.h>
using namespace std;
 
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("popcnt,avx2")

#define forn(i,n) for(int i=0; i<(n); ++i)
#define pb push_back
#define pi pair<int,int>
#define f first
#define s second 
using ll = long long;
const int N=2005;
ll dp[N];

int solve(int n, int k, int* v){
    const int mod = 1e9+7;

    deque<pi> s;
    deque<pi> d;
    ll ans=0;
    forn(i,n) {
        if (s.size() && s[0].s<=i-k) s.pop_front();
        if (d.size() && d[0].s<=i-k) d.pop_front();
        int tmp;
        while (s.size() && s.back().f <= v[i]) {
            s.pop_back();
        }
        if (s.size()) {
            while (d.size() && d.back().s > s.back().s) d.pop_back();
        } else {
            while (d.size()>1) d.pop_back();
        }
        s.pb({v[i],i});
        dp[i]=s[0].f;
        if (i-k>=0) dp[i]+=dp[i-k];
        if (d.size()) dp[i] = min(dp[i],1ll*v[i]+d.back().f);
        d.pb({dp[i],i});
        ans=(ans*23)%mod;
        ans=(ans+dp[i])%mod;
    }
    return ans;
}

Compilation message

peru.cpp: In function 'int solve(int, int, int*)':
peru.cpp:26:13: warning: unused variable 'tmp' [-Wunused-variable]
   26 |         int tmp;
      |             ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -