Submission #859616

#TimeUsernameProblemLanguageResultExecution timeMemory
859616Tudy006Peru (RMI20_peru)C++14
0 / 100
2 ms2396 KiB
#include <bits/stdc++.h> #include "peru.h" using namespace std; const int NMAX = 2500000; const int MOD = 1e9 + 7; long long dp[NMAX]; int solve( int n, int k, int* v ) { deque <int> dq; // cout << n << ' ' << k << endl; for ( int i = 0; i < n; i ++ ) { while ( !dq.empty() && v[dq.back()] <= v[i] ) dq.pop_back(); dq.push_back( i ); // cout << i << ": "; // for ( auto x : dq ) cout << x << ' '; // cout << endl; dp[i] = v[dq.front()] + ( i >= k ? dp[i - k] : 0 ); for ( int j = 1; j <(int) dq.size(); j ++ ) { dp[i] = min( dp[i], dp[dq[j - 1]] + v[dq[j]] ); } } int ans = 0; for ( int i = 0; i < n; i ++ ) { ans = ( (long long)ans * 23 + dp[i] ) % MOD; // cout << dp[i] << ' '; } // cout << endl; return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...