Submission #1072731

#TimeUsernameProblemLanguageResultExecution timeMemory
107273112345678Fibonacci representations (CEOI18_fib)C++17
25 / 100
1 ms604 KiB
#include <bits/stdc++.h> using namespace std; const int nx=105, mod=1e9+7; #define ll long long ll n, a[nx], dp[nx][2], lst, cur, sz; set<ll> s; void add(ll x) { if (x!=1&&s.find(x-1)!=s.end()) s.erase(x-1), add(x+1); else if (s.find(x+1)!=s.end()) s.erase(x+1), add(x+2); else if (s.find(x)!=s.end()) { if (x==1) s.erase(x), add(2); else if (x==2) s.erase(x), add(1), add(3); else s.erase(x), add(x-2), add(x+1); } else s.insert(x); } ll cost(ll x, ll y) { return (y-x-1)/2; } int main() { cin.tie(NULL)->sync_with_stdio(false); cin>>n; s.insert(0); dp[0][0]=1; for (int i=1; i<=n; i++) { cin>>a[i]; add(a[i]); /* cout<<"set "; for (auto x:s) cout<<x<<' '; cout<<'\n'; */ auto itr=s.begin(); sz=s.size()-1; for (int j=1; j<=sz; j++) { lst=*(itr++); cur=*itr; dp[j][0]=(dp[j-1][0]+dp[j-1][1])%mod; dp[j][1]=(dp[j-1][0]*cost(lst, cur)+dp[j-1][1]*cost(lst-1, cur)); //cout<<"cur "<<cur<<' '<<dp[j][0]<<' '<<dp[j][1]<<'\n'; } cout<<(dp[sz][0]+dp[sz][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...