Submission #538222

#TimeUsernameProblemLanguageResultExecution timeMemory
538222AdamGSPeru (RMI20_peru)C++17
18 / 100
646 ms12644 KiB
#include "peru.h" #include<bits/stdc++.h> using namespace std; typedef long long ll; #define rep(a, b) for(int a = 0; a < (b); ++a) #define st first #define nd second #define pb push_back #define all(a) a.begin(), a.end() const ll MOD=1e9+7, LIM=25e5+7, INF=1e18+7; ll dp[LIM], tr[4*LIM], N=1; vector<pair<ll,int>>V; ll cnt(int l, int r) { l+=N; r+=N; ll ans=max(tr[l], tr[r]); while(l/2!=r/2) { if(l%2==0) ans=max(ans, tr[l+1]); if(r%2==1) ans=max(ans, tr[r-1]); l/=2; r/=2; } return ans; } int solve(int n, int k, int* v){ while(N<n) N*=2; rep(i, n) tr[N+i]=v[i]; for(int i=N-1; i>=0; --i) tr[i]=max(tr[2*i], tr[2*i+1]); rep(i, k) { dp[i]=cnt(0, i); while(V.size() && v[i]>=V.back().st) V.pop_back(); V.pb({v[i], i}); } for(int i=k; i<n; ++i) { while(V.size() && v[i]>=V.back().st) V.pop_back(); V.pb({v[i], i}); dp[i]=dp[i-k]+cnt(i-k+1, i); for(int j=1; j<V.size(); ++j) { if(V[j].nd>i-k) dp[i]=min(dp[i], dp[max(V[j-1].nd, i-k)]+V[j].st); } } ll ans=0; rep(i, n) ans=(ans*23+dp[i])%MOD; return ans; }

Compilation message (stderr)

peru.cpp: In function 'int solve(int, int, int*)':
peru.cpp:36:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     for(int j=1; j<V.size(); ++j) {
      |                  ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...