Submission #1225070

#TimeUsernameProblemLanguageResultExecution timeMemory
1225070dostsFibonacci representations (CEOI18_fib)C++20
50 / 100
4094 ms3940 KiB
#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2")
#define int long long
#define pii pair<int,int>
#define vi vector<int>
#define ff first
#define ss second
#define sp << " " <<
#define all(x) x.begin(),x.end()
#define big(x) ((int)(x.size()))
using namespace std;
const int MOD = 1e9+7, LIM = 1e6+1, inf = 2e9;

const int N = 1e5+1;

int add(int x,int y) {
    if ((x + y) >= MOD) return x + y - MOD;
    return x + y;
}

int mult(int x,int y) {
    return (1LL * x * y) % MOD;
}
set<int> posy{0};
void ins(int p) {
    if (!posy.count(p)) {
        posy.insert(p);
        if (p && posy.count(p) && posy.count(p+1)) {
            posy.erase(p),posy.erase(p+1);
            ins(p+2);
        }
        if (p>1 && posy.count(p) && posy.count(p-1)) {
            posy.erase(p),posy.erase(p-1);
            ins(p+1);
        }
        return;
    }
    if (p == 1) {
        posy.erase(p);
        ins(2);
        return;
    }
    if (p == 2) {
        posy.erase(p);
        ins(1),ins(3);
        return;
    }
    posy.erase(p);
    ins(p+1),ins(p-2);
};

void solve() {
    int n;
    cin >> n;
    vi a(n+1);
    for (int i=1;i<=n;i++) cin >> a[i];
    int dp[n+2][2]{};
    for (int ii=1;ii<=n;ii++) {
        ins(a[ii]);
        vi pos = vi(all(posy));
        for (int i=0;i<=ii+1;i++) for (int j = 0;j<2;j++) dp[i][j] = 0;
        dp[1][0] = 1;
        for (int i = 1;i<=big(pos);i++) {
            for (int j = 0;j<2;j++) {
                if (!dp[i][j]) continue;
                if (i == big(pos)) continue;
                int ps = pos[i-1]-j;
                int nxt = pos[i];
                dp[i+1][0] = add(dp[i+1][0],dp[i][j]);
                dp[i+1][1] = add(dp[i+1][1],mult((nxt-ps-1)/2,dp[i][j]));
            }
        }
        cout << add(dp[big(pos)][0],dp[big(pos)][1]) << '\n';
    }
    
}   

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    #ifdef Dodi
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    #endif
    int t = 1;
    //cin >> t;
    while (t --> 0) solve();
}
#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...