Submission #582533

#TimeUsernameProblemLanguageResultExecution timeMemory
582533amunduzbaevFibonacci representations (CEOI18_fib)C++17
50 / 100
1 ms468 KiB
#include "bits/stdc++.h" using namespace std; #define ar array typedef int64_t ll; #define int ll const int N = 100; const int mod = 1e9 + 7; int a[N]; signed main(){ ios::sync_with_stdio(0); cin.tie(0); int n; cin>>n; for(int i=0;i<n;i++){ cin>>a[i]; } set<int> ss; function<void(int)> add = [&](int x){ if(ss.count(x)){ ss.erase(x); add(x + 1); if(x > 2) add(x - 2); else if(x == 2) add(x - 1); return; } if(ss.count(x + 1)){ ss.erase(x + 1); add(x + 2); return; } if(ss.count(x - 1)){ ss.erase(x - 1); add(x + 1); return; } ss.insert(x); }; for(int i=0;i<n;i++){ add(a[i]); vector<int> f; for(auto x : ss) f.push_back(x); //~ for(auto x : f) cout<<x<<" "; //~ cout<<"\n"; ar<int, 2> dp {}; dp[0] = 1; int m = f.size(), last = 0; for(int i=0,j=0;i<m;){ ar<int, 2> tp {}; while(j<m && (j == i || f[j] == f[j-1] + 2)) j++; int p = f[i] - last - 1; tp[0] = dp[0] * 1ll * (1 + (p / 2) * 1ll * (j - i - 1) % mod) % mod; tp[0] = (tp[0] + dp[1] * 1ll * (1 + ((p + 1) / 2) * 1ll * (j - i - 1) % mod)) % mod; tp[1] = dp[0] * 1ll * (p / 2) % mod; tp[1] = (tp[1] + dp[1] * 1ll * ((p + 1) / 2)) % mod; swap(tp, dp); //~ cout<<dp[0]<<" "<<dp[1]<<"\n"; last = f[j - 1]; i = j; } //~ cout<<dp[0]<<" "<<dp[1]<<"\n"; cout<<(dp[0] + dp[1]) % mod<<"\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...