Submission #636586

#TimeUsernameProblemLanguageResultExecution timeMemory
636586stoyan_malininPeru (RMI20_peru)C++14
Compilation error
0 ms0 KiB
#include "peru.h" #ifdef _LOCAL_ #include "grader.cpp" #endif // _LOCAL_ #include <vector> #include <deque> using namespace std; int rmq(int l, int r, const int *a) { int maxVal = a[l]; for(int i = l+1;i<=r;i++) maxVal = max(maxVal, a[i]); return maxVal; } int convertToAns(const vector<long long> &dp) { long long p23 = 1, ans = 0; const long long mod = 1e9 + 7; for(int i = dp.size()-1;i>=0;i--) { ans = (ans + (dp[i]%mod)*p23)%mod; p23 = (p23*23)%mod; } return ans; } int solve(int n, int k, int* a) { vector <long long> dp(n); dp[0] = a[0]; deque <int> opt; int64_t prefMaxVal = a[0]; for(int i = 1;i<n;i++) { while(opt.empty()==false && dp[opt.back()]+rmq(opt.back()+1, i, a)>dp[i-1]+a[i]) { //cout << "pop_back: " << opt.back() << '\n'; opt.pop_back(); } opt.push_back(i-1); while(opt.empty()==false && i-opt.front()>k) opt.pop_front(); while(opt.size()>=2 && dp[opt[0]]+rmq(opt[0]+1, i, a)>dp[opt[1]]+rmq(opt[1]+1, i, a)) opt.pop_front(); //cout << i << ": "; //for(int x: opt) cout << x << " "; //cout << '\n'; dp[i] = dp[opt.front()] + rmq(opt.front()+1, i, a); prefMaxVal = max(prefMaxVal, (int64_t)a[i]); if(i<k) dp[i] = min(dp[i], prefMaxVal); //cout << "dp[" << i << "] = " << dp[i] << '\n'; } return convertToAns(dp); }

Compilation message (stderr)

peru.cpp: In function 'int solve(int, int, int*)':
peru.cpp:40:5: error: 'int64_t' was not declared in this scope
   40 |     int64_t prefMaxVal = a[0];
      |     ^~~~~~~
peru.cpp:58:9: error: 'prefMaxVal' was not declared in this scope
   58 |         prefMaxVal = max(prefMaxVal, (int64_t)a[i]);
      |         ^~~~~~~~~~
peru.cpp:58:47: error: expected ')' before 'a'
   58 |         prefMaxVal = max(prefMaxVal, (int64_t)a[i]);
      |                         ~                     ^
      |                                               )