답안 #1072732

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1072732 2024-08-24T03:36:11 Z 12345678 Fibonacci representations (CEOI18_fib) C++17
50 / 100
1 ms 604 KB
#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]);
        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))%mod;
            //cout<<"cur "<<cur<<' '<<dp[j][0]<<' '<<dp[j][1]<<'\n';
        }
        cout<<(dp[sz][0]+dp[sz][1])%mod<<'\n';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 432 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 432 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Runtime error 1 ms 604 KB Execution killed with signal 11
25 Halted 0 ms 0 KB -