Why getting tle with this?

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

int CONST = 1000000007;
int a[10000000];

ll getWays(ll n, ll m){

if(a[n]!=-1){
	return a[n];
}

if(n>=0 and n<m){
	return 1;
}

if(n<0){
	return 0;
}

if(n==m){
	return 2;
}

ll ans = ((getWays(n-1,m)%CONST)+(getWays(n-m,m)%CONST))%CONST;
a[n] = ans;
return ans;

}

int main() {

int t;
cin>>t;
while(t--){
	memset(a,-1,sizeof(a));
	ll n,m;
	cin>>n>>m;
	cout<<getWays(n,m)<<endl;
}
return 0;

}

and it passes all test cases when I reduced my array “a” size to 10005 what is the relation with array size?

Hey @talhashamim001

Here reduce array size to 10^5
Otherwise u are using memset on array of size 10^7 which is consuming time

okk I thought that only thank tou

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.