QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#788634#9225. Fibonacci Fusionucup-team2179#Compile Error//C++232.3kb2024-11-27 17:44:032024-11-27 17:44:07

Judging History

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

  • [2024-11-27 17:44:07]
  • 评测
  • [2024-11-27 17:44:03]
  • 提交

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 = 2e6 + 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

answer.code:94:1: fatal error: error writing to /tmp/ccTnoVR0.s: File too large
   94 | }
      | ^
compilation terminated.