Submission #467008

# Submission time Handle Problem Language Result Execution time Memory
467008 2021-08-21T09:38:29 Z idk321 Fibonacci representations (CEOI18_fib) C++17
0 / 100
4000 ms 332 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int N = 110;
__int128 fib[N];
const int MOD = 1000000007;


string num128toint(__int128 num) {
    string res = "";
    while (num > 0) {
        res += (num % 10) + '0';
        num /= 10;
    }
    for (int i = 0, j = res.size() - 1; i < j; i++, j--) {
        swap(res[i], res[j]);
    }

    return res;
}

void calcFib() {
    for (int i = 3; i < N; i++) {
        fib[i] = fib[i - 1] + fib[i - 2];

    }
}

int calcFor(__int128 num, int from) {
    if (num == 0) return 1;
    if (from <= 0) return 0;
    int cur = from;
    while (fib[cur] > num) cur--;
    int res = calcFor(num - fib[cur], cur - 2);
    res %= MOD;
    if (cur > 2) res += calcFor(num - fib[cur], cur - 3);
    res %= MOD;
    if (cur > 1) res += calcFor(num - fib[cur - 1], cur - 3);
    res %= MOD;
    return res;
}

int main() {
    fib[1] = 1;
    fib[2] = 2;
    calcFib();

    __int128 num = fib[N - 1] * 100;

    int n;
    cin >> n;
    __int128 sum = 0;
    for (int i = 0; i < n; i++) {
        int ind;
        cin >> ind;
        sum += fib[ind];
        cout << calcFor(sum, N - 1) << "\n";
    }
}

Compilation message

fib.cpp: In function 'int main()':
fib.cpp:50:14: warning: unused variable 'num' [-Wunused-variable]
   50 |     __int128 num = fib[N - 1] * 100;
      |              ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4030 ms 204 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 332 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -