Submission #898681

# Submission time Handle Problem Language Result Execution time Memory
898681 2024-01-05T02:37:27 Z math_rabbit_1028 Fibonacci representations (CEOI18_fib) C++14
50 / 100
4000 ms 1512 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll MOD = 1e9 + 7;

int n, arr[101010];
ll dp[101010];

vector<int> one(vector<int> vec) {
    vector<int> ret;
    while (true) {
        int f = 0;
        for (int i = 2; i < vec.size(); i++) {
            if (vec[i-1] + 1 == vec[i]) {
                f = i;
                break;
            }
        }
        if (f == 0) break;
        for (int i = 0; i < vec.size(); i++) {
            if (i == f || i == f-1) continue;
            ret.push_back(vec[i]);
        }
        ret.push_back(vec[f]+1);
        sort(ret.begin(), ret.end());
        vec = ret;
        ret.clear();
    }
    return vec;
}

vector<int> zero(vector<int> vec) {
    vector<int> ret;
    while (true) {
        int f = 0;
        for (int i = 2; i < vec.size(); i++) {
            if (vec[i-1] == vec[i]) {
                f = i;
                break;
            }
        }
        if (f == 0) break;
        for (int i = 0; i < vec.size(); i++) {
            if (i == f || i == f-1) continue;
            ret.push_back(vec[i]);
        }
        if (vec[f] == 1) ret.push_back(2);
        else if (vec[f] == 2) { ret.push_back(1); ret.push_back(3); }
        else { ret.push_back(vec[f]-2); ret.push_back(vec[f]+1); }
        sort(ret.begin(), ret.end());
        vec = ret;
        ret.clear();
    }
    return vec;
}

void solve(vector<int> vec) {
    sort(vec.begin(), vec.end());
    vec = zero(vec);
    vec = one(vec);
    vec = zero(vec);
    vec = one(vec);

    int k = vec.size()-1;
    //for (int i = 1; i <= k; i++) cout << vec[i] << " "; cout << "\n";
    for (int i = 0; i <= k; i++) dp[i] = 0;

    dp[0] = 1;
    dp[1] = (vec[1] + 1) / 2;
    for (int i = 2; i <= k; i++) {
        ll d = vec[i] - vec[i - 1];
        if (d % 2 == 0) dp[i] = (dp[i-1] * ((d+3)/2) % MOD + MOD - dp[i-2]) % MOD;
        else dp[i] = dp[i-1] * ((d+1)/2) % MOD;
    }

    cout << dp[k] << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n;
    for (int i = 1; i <= n; i++) cin >> arr[i];

    vector<int> vec(1, 0);
    for (int i = 1; i <= n; i++) {
        vec.push_back(arr[i]);
        solve(vec);
    }

    return 0;
}

Compilation message

fib.cpp: In function 'std::vector<int> one(std::vector<int>)':
fib.cpp:13:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |         for (int i = 2; i < vec.size(); i++) {
      |                         ~~^~~~~~~~~~~~
fib.cpp:20:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |         for (int i = 0; i < vec.size(); i++) {
      |                         ~~^~~~~~~~~~~~
fib.cpp: In function 'std::vector<int> zero(std::vector<int>)':
fib.cpp:36:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |         for (int i = 2; i < vec.size(); i++) {
      |                         ~~^~~~~~~~~~~~
fib.cpp:43:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |         for (int i = 0; i < vec.size(); i++) {
      |                         ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 3 ms 344 KB Output is correct
8 Correct 20 ms 480 KB Output is correct
9 Correct 16 ms 348 KB Output is correct
10 Correct 18 ms 480 KB Output is correct
11 Correct 21 ms 600 KB Output is correct
12 Correct 150 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 3 ms 344 KB Output is correct
8 Correct 20 ms 480 KB Output is correct
9 Correct 16 ms 348 KB Output is correct
10 Correct 18 ms 480 KB Output is correct
11 Correct 21 ms 600 KB Output is correct
12 Correct 150 ms 468 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 10 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 184 ms 468 KB Output is correct
20 Correct 8 ms 348 KB Output is correct
21 Correct 6 ms 348 KB Output is correct
22 Correct 7 ms 480 KB Output is correct
23 Correct 9 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Execution timed out 4057 ms 1512 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 3 ms 344 KB Output is correct
8 Correct 20 ms 480 KB Output is correct
9 Correct 16 ms 348 KB Output is correct
10 Correct 18 ms 480 KB Output is correct
11 Correct 21 ms 600 KB Output is correct
12 Correct 150 ms 468 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 10 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 184 ms 468 KB Output is correct
20 Correct 8 ms 348 KB Output is correct
21 Correct 6 ms 348 KB Output is correct
22 Correct 7 ms 480 KB Output is correct
23 Correct 9 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Execution timed out 4057 ms 1512 KB Time limit exceeded
26 Halted 0 ms 0 KB -