제출 #1126525

#제출 시각아이디문제언어결과실행 시간메모리
1126525wjankowskiFibonacci representations (CEOI18_fib)C++20
50 / 100
4091 ms1792 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long constexpr ll mod = 1e9+7; set <int> s; void add(int a) { if(a == -1) return; if(a == 0) a++; if(s.count(a+1)) s.erase(a+1), add(a+2); else if(s.count(a-1)) s.erase(a-1), add(a+1); else if(s.count(a)) s.erase(a), add(a-2), add(a+1); else s.insert(a); } int main() { cin.tie(0) -> ios_base::sync_with_stdio(0); int n; cin >> n; for(int i=1; i<=n; i++) { int a; cin >> a; add(a); int prev=0; ll dp[2]; dp[0] = 1, dp[1] = 0; for(int x:s) { pair <ll,ll> w = {(dp[0]+dp[1])%mod,((x-prev)/2*dp[1] + (x-prev-1)/2*dp[0])%mod}; dp[0] = w.first; dp[1] = w.second; prev=x; } 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...