QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#655099#9225. Fibonacci Fusionreal_sigma_team#RE 0ms0kbC++172.0kb2024-10-19 00:31:462024-10-19 00:31:47

Judging History

你现在查看的是最新测评结果

  • [2024-10-19 00:31:47]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-10-19 00:31:46]
  • 提交

answer

#include<bits/stdc++.h>


const int K = 5;
std::array<uint64_t, K> MOD;

int64_t add(int64_t a, int64_t b, uint64_t mod) {
    return a + b >= mod ? a + b - mod : a + b;
}
int64_t sub(int64_t a, int64_t b, uint64_t mod) {
    return a >= b ? a - b : a + mod - b;
}
int64_t mul(int64_t a, int64_t b, uint64_t mod) {
    return (__int128)a * b % mod;
}

using num = std::array<uint64_t, K>;

num add(num a, num b) {
    for (int i = 0; i < K; ++i) {
        a[i] = add(a[i], b[i], MOD[i]);
    }
    return a;
}
num sub(num a, num b) {
    for (int i = 0; i < K; ++i) {
        a[i] = sub(a[i], b[i], MOD[i]);
    }
    return a;
}
num mul(num a, num b) {
    for (int i = 0; i < K; ++i) {
        a[i] = mul(a[i], b[i], MOD[i]);
    }
    return a;
}

const double E = 2.7182818284590452353602874713526624977572470936999595749669676277;
const double PI = 3.1415926535897932384626433832795028841971693993751058209749445923;
const double LOVV66 = sqrtl((-7286 + 183 * E + 2729 * PI + 530 * logl(2)) / 94);

const int A = 1e7;

num fib[A];

int main() {
    std::cin.tie(nullptr)->sync_with_stdio(false);

    fib[0].fill(0);
    fib[1].fill(1);
    for (int i = 2; i < A; ++i) {
        fib[i] = add(fib[i - 1], fib[i - 2]);
    }

    int n;
    std::cin >> n;
    std::vector<std::string> a(n);
    for (auto& i : a) std::cin >> i;
    std::sort(a.begin(), a.end(), [&](auto& i, auto& j) {
        if (i.size() != j.size()) return i.size() < j.size();
        return i < j;
    });
    std::map<num, int> mp;
    long long ans = 0;
    for (int i = 0; i < n; ++i) {
        int q = a[i].size() * LOVV66;
        num h1; h1.fill(0);
        for (auto c : a[i]) {
            num ten; ten.fill(10);
            num ch; ch.fill(c - '0');
            h1 = add(mul(h1, ten), ch);
        }
        for (int j = std::max(0, q - 5); j <= q + 10; ++j) {
            ans += mp[sub(fib[j], h1)];
        }
        mp[h1]++;
    }
    std::cout << ans;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

6
50
8
8
5
72
354224848179261915070

output:


result: