답안 #467012

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
467012 2021-08-21T09:47:24 Z idk321 Fibonacci representations (CEOI18_fib) C++17
5 / 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;
    if (cur > 1 && num >= fib[cur] + fib[cur - 1]) res += calcFor(num - fib[cur] - fib[cur - 1], cur - 2);
    return res;
}

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


    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";
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 2 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 2 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Execution timed out 4065 ms 204 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4067 ms 204 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 2 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Execution timed out 4065 ms 204 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 332 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 2 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Execution timed out 4065 ms 204 KB Time limit exceeded
9 Halted 0 ms 0 KB -