Submission #444147

# Submission time Handle Problem Language Result Execution time Memory
444147 2021-07-13T07:12:29 Z LittleCube Fibonacci representations (CEOI18_fib) C++14
0 / 100
1 ms 332 KB
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define F first
#define S second
using namespace std;

const ll MOD = 1000000007;
map<int, int> mp;
int dp[100005][2] = {{0}};

void valid(int x)
{
    while ((x == 1 && mp[x] > 1) || (mp.find(x) != mp.end() && mp.find(x + 1) != mp.end()))
    {
        if (x == 1 && mp[x] > 1)
        {
            mp[x + 1] += mp[x] / 2;
            mp[x] %= 2;
            if (mp[x] == 0)
                mp.erase(mp.find(x));
        }
        else if (mp[x] < mp[x + 1])
        {
            mp[x + 2] += mp[x];
            mp[x + 1] -= mp[x];
            mp.erase(mp.find(x));
        }
        else if (mp[x] == mp[x + 1])
        {
            mp[x + 2] += mp[x];
            mp.erase(mp.find(x + 1));
            mp.erase(mp.find(x));
        }
        else
        {
            mp[x + 2] += mp[x + 1];
            mp[x] -= mp[x + 1];
            mp.erase(mp.find(x + 1));
        }
        x++;
    }
}

signed main()
{
    int N;
    cin >> N;
    for (int i = 1; i <= N; i++)
    {
        int x;
        cin >> x;
        mp[x]++;
        valid(x);
        valid(x - 1);
        auto iter = mp.begin();
        if (iter->S >= 3)
            dp[1][0] = dp[1][1] = 0;
        else if (iter->S == 2)
        {
            if (iter->F >= 3)
                dp[1][1] = (iter->F - 1) / 2;
            else
                dp[1][1] = 0;
            dp[1][0] = 0;
        }
        else
        {
            dp[1][1] = (iter->F - 1) / 2;
            dp[1][0] = 1;
        }
        ++iter;

        for (int i = 2; i <= mp.size(); i++)
        {
            if (iter->S >= 3)
                dp[i][0] = dp[i][1] = 0;
            else if (iter->S == 2 && prev(iter)->S == 2)
            {
                dp[i][1] = (dp[i - 1][1] * ((iter->F - prev(iter)->F - 1) / 2)) % MOD;
                dp[i][0] = 0;
            }
            else if (iter->S == 2 && prev(iter)->S == 1)
            {
                dp[i][1] = (dp[i - 1][1] * ((iter->F - prev(iter)->F) / 2) +
                            dp[i - 1][0] * ((iter->F - prev(iter)->F - 1) / 2)) %
                           MOD;
                dp[i][0] = 0;
            }
            else if (iter->S == 1 && prev(iter)->S == 2)
            {
                dp[i][1] = dp[i - 1][1] * ((iter->F - prev(iter)->F - 1) / 2) % MOD;
                dp[i][0] = dp[i - 1][1];
            }
            else if (iter->S == 1 && prev(iter)->S == 1)
            {
                dp[i][1] = (dp[i - 1][1] * ((iter->F - prev(iter)->F) / 2) +
                            dp[i - 1][0] * ((iter->F - prev(iter)->F - 1) / 2)) %
                           MOD;
                dp[i][0] = (dp[i - 1][1] + dp[i - 1][0]) % MOD;
            }
            ++iter;
        }
        //for (pii i : mp)
            //cout << "(" << i.F << ", " << i.S << ") ";
        cout << (dp[mp.size()][0] + dp[mp.size()][1]) % MOD << '\n';
    }
}

Compilation message

fib.cpp: In function 'int main()':
fib.cpp:74:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::map<int, int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |         for (int i = 2; i <= mp.size(); i++)
      |                         ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -