This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define int long long
#define ii pair<int,int>
#define F first
#define S second
#define du long double
using namespace std;
const int N=40;
int a[N];
int f[N];
map<ii,int> mp;
int bc(int sum,int i)
{
if(sum<0)return 0;
// cout<<sum<<" "<<i<<endl;
if(mp.count({sum,i})){
return mp[{sum,i}];
}
if(i==0){
return sum==0;
}
int ret=0;
ret+=bc(sum-f[i],i-1);
ret+=bc(sum,i-1);
return mp[{sum,i}]=ret;
}
void solve()
{
int n;
cin>>n;
f[1]=1;
f[2]=2;
for(int i=3;i<=24;i++){
f[i]=f[i-1]+f[i-2];
}
int sum=0;
while(n--){
int a;
cin>>a;
sum+=f[a];
// mp.clear();
int ans=bc(sum,24);
cout<<ans<<endl;
}
}
main()
{
int t=1;
//cin>>t;
while(t--)solve();
}
Compilation message (stderr)
fib.cpp:46:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
46 | main()
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |