#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define ff first
#define ss second
ll ttt;
const ll INF=1e18;
const ll MOD=1e9+7;
const ll N=100007;
ll n,m,k;
int a[N];
vector<__int128_t>fi;
ll dp[N][2];
void calc_fi(int len){
fi.push_back(1);
fi.push_back(2);
for(int i=2;i<=len;i++){
fi.push_back(fi[i-1]+fi[i-2]);
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
cin>>n;
calc_fi(150);
__int128_t sum=0;
bool st3=false;
for(int i=0;i<n;i++){
cin>>a[i];
if(a[i]>100)st3=true;
}
if(st3){
vector<int>p;
for(int i=0;i<n;i++){
p.push_back(a[i]);
sort(p.begin(),p.end());
// for(int x:p)cout<<x<<" ";
// cout<<endl;
int lst=0;
dp[0][0]=1;
dp[0][1]=0;
for(int i=0;i<p.size();i++){
dp[i+1][0]=dp[i][0]+dp[i][1];
int diff=p[i]-lst;
if(diff>=2){
if(diff%2==0){
diff/=2;
dp[i+1][1]=(dp[i][0]+dp[i][1])*(diff-1)+dp[i][1];
}
else{
diff/=2;
dp[i+1][1]=(dp[i][0]+dp[i][1])*diff;
}
}
else{
dp[i+1][1]=0;
}
dp[i+1][0]%=MOD;
dp[i+1][1]%=MOD;
lst=p[i];
// cout<<dp[i+1][0]<<" "<<dp[i+1][1]<<endl;
}
cout<<(dp[p.size()][0]+dp[p.size()][1])%MOD<<endl;
}
return 0;
}
for(int i=0;i<n;i++){
sum+=fi[a[i]-1];
vector<int>p;
__int128_t tmp=sum;
while(tmp!=0){
auto it=upper_bound(fi.begin(),fi.end(),tmp);
it--;
p.push_back(it-fi.begin()+1);
tmp-=*it;
}
reverse(p.begin(),p.end());
// for(int x:p)cout<<x<<" ";
// cout<<endl;
int lst=0;
dp[0][0]=1;
dp[0][1]=0;
for(int i=0;i<p.size();i++){
dp[i+1][0]=dp[i][0]+dp[i][1];
int diff=p[i]-lst;
if(diff>=2){
if(diff%2==0){
diff/=2;
dp[i+1][1]=(dp[i][0]+dp[i][1])*(diff-1)+dp[i][1];
}
else{
diff/=2;
dp[i+1][1]=(dp[i][0]+dp[i][1])*diff;
}
}
else{
dp[i+1][1]=0;
}
dp[i+1][0]%=MOD;
dp[i+1][1]%=MOD;
lst=p[i];
// cout<<dp[i+1][0]<<" "<<dp[i+1][1]<<endl;
}
cout<<(dp[p.size()][0]+dp[p.size()][1])%MOD<<endl;
}
}
Compilation message
fib.cpp: In function 'int main()':
fib.cpp:53:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | for(int i=0;i<p.size();i++){
| ~^~~~~~~~~
fib.cpp:94:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
94 | for(int i=0;i<p.size();i++){
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Execution timed out |
4070 ms |
1080 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |