QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#788645#9225. Fibonacci Fusionucup-team2179#TL 0ms35120kbC++232.3kb2024-11-27 17:45:292024-11-27 17:45:34

Judging History

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

  • [2024-11-27 17:45:34]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:35120kb
  • [2024-11-27 17:45:29]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define db double
#define ll __int128_t
#define pii pair<int, int>
using namespace std;
const int maxn = 1e6 + 10;
const int mod = 1e18 + 21;
struct INT {
    vector<int> arr;
    int you = 1;
} arr[maxn];
bool cmp(INT a, INT b) {
    if (a.you != b.you)
        return a.you < b.you;
    for (int i = a.you; i; i--)
        if (a.arr[i] != b.arr[i])
            return a.arr[i] < b.arr[i];
    return 1;
}
INT add(INT a, INT b) {
    INT res;
    res.you = max(a.you, b.you) + 1;
    res.arr.resize(res.you + 1);
    for (int i = 1; i <= max(a.you, b.you); i++) {
        if (a.you >= i)
            res.arr[i] += a.arr[i];
        if (b.you >= i)
            res.arr[i] += b.arr[i];
        res.arr[i + 1] += res.arr[i] / 10, res.arr[i] %= 10;
    }
    while (res.you > 1 && res.arr[res.you] == 0)
        res.you--;
    return res;
}
INT sub(INT a, INT b) {
    INT res;
    res.you = a.you;
    res.arr = a.arr;
    for (int i = 1; i <= res.you; i++) {
        res.arr[i] -= b.arr[i];
        if (res.arr[i] < 0) {
            res.arr[i + 1]--;
            res.arr[i] += 10;
        }
    }
    while (res.you > 1 && res.arr[res.you] == 0)
        res.you--;
    return res;
}
ll gethash(INT a) {
    ll res = 0;
    for (int i = 1; i <= a.you; i++)
        res = (res * 131 + a.arr[i]) % mod;
    return res;
}
map<ll, int> mp;
void solve() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        string str;
        cin >> str;
        arr[i].you = str.length();
        arr[i].arr.resize(arr[i].you + 1);
        reverse(str.begin(), str.end());
        for (int j = 1; j <= arr[i].you; j++)
            arr[i].arr[j] = str[j - 1] - '0';
    }
    sort(arr + 1, arr + 1 + n, cmp);
    INT fib1, fib2;
    fib1.you = fib2.you = 1;
    fib1.arr = {0, 1};
    fib2.arr = {0, 1};
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        while (cmp(fib2, arr[i])) {
            fib2 = add(fib1, fib2);
            fib1 = sub(fib2, fib1);
        }
        if (mp.count(gethash(sub(fib2, arr[i]))))
            ans++;
        mp[gethash(arr[i])] = 1;
    }
    cout << ans << "\n";
}
signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t = 1;
    // cin >> t;
    while (t--)
        solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 35120kb

input:

6
50
8
8
5
72
354224848179261915070

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: -100
Time Limit Exceeded

input:

28
200878223506436882933619847964496455022155117513398820563747455993172799881403389571477889821109288771413214004090719097929400406252135763028179112130390003528046316900603668569910008417315162907579003880220844686222148696041857432602133894827753998572080650383305777912447151917272483538029469449...

output:


result: