Submission #635596

#TimeUsernameProblemLanguageResultExecution timeMemory
635596martin_nedevPeru (RMI20_peru)C++14
Compilation error
0 ms0 KiB
#include "peru.h" #ifdef __LOCALTEST #include "grader.cpp" #endif // __LOCALTEST //first subtask const int MAXLOG = 12; const int MAXN = 2000; const int inf = 1e9; const int mod = 1e9+7; struct RangeMaximumQuery { int n; int log[MAXN+10]; int sparseTable[MAXLOG][MAXN+10]; RangeMaximumQuery(int n) { //precompute log array //!log[i] gives the value of log2(i) rounded down this->n = n; log[1] = 0; for (int i = 2; i <= n; i++) log[i] = log[i>>1] + 1; } void Build(int *arr) { //construct sparse table for (int i = 0; i < n; i++) sparseTable[0][i] = arr[i]; for (int lg = 1; lg <= MAXLOG; lg++) { for (int i = 0; i < n; i++) { int jump = (1<<(lg-1)); if (i+jump >= n) sparseTable[lg][i] = sparseTable[lg-1][i]; else sparseTable[lg][i] = max(sparseTable[lg-1][i], sparseTable[lg-1][i+jump]); } } } int Query(int leftQ, int rightQ) { //answering query return max(sparseTable[log[rightQ-leftQ+1]][leftQ], sparseTable[log[rightQ-leftQ+1]][rightQ-(1<<log[rightQ-leftQ+1])+1]); } }; int evaluateAnswer(const int n, int *arr) { int64_t ans = 0; for (int i = 0; i < n; i++) { ans = (ans*23 + arr[i])%mod; } return ans; } int dp1[MAXN+10][MAXN+10]; int dp2[MAXN+10]; int solve(int n, int k, int* v) { RangeMaximumQuery *rmq = new RangeMaximumQuery(n); rmq->Build(v); for (int i = 0; i < n; i++) dp2[i] = inf; dp1[0][1] = v[0]; dp2[0] = v[0]; for (int i = 1; i < n; i++) { for (int j = 1; j <= min(i+1, k); j++) { dp1[i][j] = rmq->Query(i-j+1, i) + dp2[i-j]; dp2[i] = min(dp2[i], dp1[i][j]); } } cout << evaluateAnswer(n, dp2) << endl; return 0; }

Compilation message (stderr)

peru.cpp: In member function 'void RangeMaximumQuery::Build(int*)':
peru.cpp:50:42: error: 'max' was not declared in this scope
   50 |                     sparseTable[lg][i] = max(sparseTable[lg-1][i], sparseTable[lg-1][i+jump]);
      |                                          ^~~
peru.cpp: In member function 'int RangeMaximumQuery::Query(int, int)':
peru.cpp:58:16: error: 'max' was not declared in this scope
   58 |         return max(sparseTable[log[rightQ-leftQ+1]][leftQ],
      |                ^~~
peru.cpp: In function 'int evaluateAnswer(int, int*)':
peru.cpp:66:5: error: 'int64_t' was not declared in this scope
   66 |     int64_t ans = 0;
      |     ^~~~~~~
peru.cpp:69:9: error: 'ans' was not declared in this scope
   69 |         ans = (ans*23 + arr[i])%mod;
      |         ^~~
peru.cpp:72:12: error: 'ans' was not declared in this scope
   72 |     return ans;
      |            ^~~
peru.cpp: In function 'int solve(int, int, int*)':
peru.cpp:91:30: error: 'min' was not declared in this scope
   91 |         for (int j = 1; j <= min(i+1, k); j++)
      |                              ^~~
peru.cpp:99:5: error: 'cout' was not declared in this scope
   99 |     cout << evaluateAnswer(n, dp2) << endl;
      |     ^~~~
peru.cpp:99:39: error: 'endl' was not declared in this scope
   99 |     cout << evaluateAnswer(n, dp2) << endl;
      |                                       ^~~~