Submission #582678

# Submission time Handle Problem Language Result Execution time Memory
582678 2022-06-24T09:03:34 Z 박상훈(#8369) Fibonacci representations (CEOI18_fib) C++17
25 / 100
1 ms 340 KB
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
const int MOD = 1e9+7;
__int128 fib[200];

ll pw(ll a, ll e){
    if (!e) return 1;
    ll ret = pw(a, e/2);
    if (e&1) return ret*ret%MOD*a%MOD;
    return ret*ret%MOD;
}

ll INV(ll x){
    return pw(x, MOD - 2);
}

vector<int> convert(__int128 x){
    vector<int> ret;
    for (int i=120;i>=1;i--) if (x>=fib[i]){
        ret.push_back(i);
        x -= fib[i];
    }
    ret.push_back(0);
    reverse(ret.begin(), ret.end());
    return ret;
}

int main(){
    int n;
    scanf("%d", &n);

    fib[0] = fib[1] = 1;
    for (int i=2;i<=120;i++) fib[i] = fib[i-1] + fib[i-2];

    vector<int> a = {0};
    __int128 cur = 0;

    for (int i=1;i<=n;i++){
        int x;
        scanf("%d", &x);
        /*a.push_back(x);
        sort(a.begin(), a.end());
        */
        cur += fib[x];
        a = convert(cur);

        vector<ll> dp1(a.size()), dp2(a.size());
        dp1[0] = dp2[0] = 1;

        for (int i=1;i<(int)a.size();i++){
            dp1[i] = dp1[i-1] * ((a[i] - a[i-1] + 1) / 2) % MOD;
            if (a[i]%2==a[i-1]%2) dp1[i] = (dp1[i] + dp1[i-1] - dp2[i-1] + MOD) % MOD;

            dp2[i] = dp1[i-1];
        }

        printf("%lld\n", dp1.back());
    }
    return 0;
}

Compilation message

fib.cpp: In function 'int main()':
fib.cpp:32:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
fib.cpp:42:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |         scanf("%d", &x);
      |         ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 232 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 232 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 232 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Incorrect 0 ms 212 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 232 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Incorrect 0 ms 212 KB Output isn't correct
14 Halted 0 ms 0 KB -