CSES - Aalto Competitive Programming 2024 - wk1 - Wed - Results
Submission details
Task:Scorpion and frogs
Sender:aalto2024a_004
Submission time:2024-09-04 17:16:39 +0300
Language:C++ (C++11)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int scorpion_cross_river(int)':
input/code.cpp:19:20: error: 'dp' was not declared in this scope
   19 |             sum -= dp[i + 2];
      |                    ^~

Code

#include <iostream>
#include <vector>

using namespace std;

int scorpion_cross_river(int n) {

    vector<int> tb(n + 1);
    tb[n] = 1;

    int sum = 1;

    for (int i = n - 1; i >= 0; i--) {
        tb[i] = sum % 998244353 ;
        
        sum += tb[i];

        if (i + 2 <= n) {
            sum -= dp[i + 2];
        }
        sum = (sum + 998244353) % 998244353;
       
    }

    return tb[0];
}


int main() {
    int n;
    cin >> n;
    int result = scorpion_cross_river(n);
    cout << result << endl;
    return 0;
}