CSES - Aalto Competitive Programming 2024 - wk12 - Wed - Results
Submission details
Task:Rabbits
Sender:joaquimballester
Submission time:2024-11-27 17:36:11 +0200
Language:C++ (C++11)
Status:COMPILE ERROR

Compiler report

input/code.cpp:5:4: error: expected initializer before 'rabbits'
    5 | ll rabbits(ll month, vector<ll>& dp) {
      |    ^~~~~~~
input/code.cpp: In function 'int main()':
input/code.cpp:16:8: error: expected initializer before 'a'
   16 |     ll a, b;
      |        ^
input/code.cpp:17:12: error: 'a' was not declared in this scope
   17 |     cin >> a >> b;
      |            ^
input/code.cpp:17:17: error: 'b' was not declared in this scope
   17 |     cin >> a >> b;
      |                 ^
input/code.cpp:19:14: error: template argument 1 is invalid
   19 |     vector<ll> dp(1001, -1);
      |              ^
input/code.cpp:19:14: error: template argument 2 is invalid
input/code.cpp:19:27: error: expression list treated as compound expression in initializer [-fpermissive]
   19 |     vector<ll> dp(1001, -1);
      |                           ^
input/code.cpp:19:19: warning: left operand of comma operator has no effect [-Wunused-value]
   19 |     vector<ll> dp(1001, -1);
      |...

Code

#include <bits/stdc++.h>
#define ll long long ll
using namespace std;

ll rabbits(ll month, vector<ll>& dp) {
    if (month == 0) return 0;
    if (month == 1) return 1;

    if (dp[month] != -1) return dp[month];

    dp[month] = rabbits(month - 1, dp) + rabbits(month - 2, dp);
    return dp[month];
}

int main() {
    ll a, b;
    cin >> a >> b;

    vector<ll> dp(1001, -1);  

    ll month = 0;
    ll sol = 0;
    ll num_rabbits = 0;

    while (num_rabbits < b) {
        num_rabbits = rabbits(month, dp);  
        if (num_rabbits >= a) {
            ++sol;
        }
        ++month;
    }

    cout << sol << endl;
    return 0;
}