QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#772549#9225. Fibonacci FusionRaresFelixRE 1388ms158788kbC++231.9kb2024-11-22 20:10:592024-11-22 20:10:59

Judging History

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

  • [2024-11-22 20:10:59]
  • 评测
  • 测评结果:RE
  • 用时:1388ms
  • 内存:158788kb
  • [2024-11-22 20:10:59]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using pl = pair<ll, ll>;

const ll MOD1 = 1e9 + 7;
const ll MOD2 = 1e9 + 9;
const double INF = 1e9;

struct nr {
    double l;
    ll r1, r2;

    nr(int v = 0) {
        r1 = v % MOD1;
        r2 = v % MOD2;
        if(!v) {
            l = -INF;
            return;
        }
        l = log10(double(v));
    }

    nr(string s) {
        r1 = r2 = 0;
        l = 0;
        double val = 0;
        double factor = 1.;
        for(auto it : s) {
            val += (it - '0') * factor;
            r1 = (r1 * 10 + it - '0') % MOD1;
            r2 = (r2 * 10 + it - '0') % MOD2;
            factor /= 10;
        }
        l = log10(val) + (double)s.size() - 1;
    }

    friend istream &operator>>(istream &i, nr &that) {
        string s;
        i >> s;
        that = nr(s);
        return i;
    }
};

pl add(pl a, pl b) {
    return pl({(a.first + b.first) % MOD1, (a.second + b.second) % MOD2});
}

pl sub(pl a, pl b) {
    return pl({(a.first - b.first + MOD1) % MOD1, (a.second - b.second + MOD2) % MOD2});
}


int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<nr> V(n);
    for(int i = 0; i < n; ++i) cin >> V[i];
    sort(V.begin(), V.end(), [&](auto a, auto b) { return a.l < b.l; });
    pl a(0, 0), b(1, 1), c;

    const int NFIBO = 4e6;

    vector<pl> RestF;

    for(int i = 0; i < NFIBO; ++i) {
        RestF.push_back(a);
        c = add(a, b);
        a = b;
        b = c;
    }

    map<pl, int> M;
    ll re = 0;
    for(int i = 0; i < n; ++i) {
        int bound = int(V[i].l * 4.784971966781666);
        pl v = pl(V[i].r1, V[i].r2);
        for(int j = bound - 1; j < bound + 5; ++j) {
            if(j < 0) continue;
            auto c = sub(RestF[j], v);
            re += M[c];
        }
        ++M[v];
    }

    cout << re << "\n";
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 20ms
memory: 69304kb

input:

6
50
8
8
5
72
354224848179261915070

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: 0
Accepted
time: 48ms
memory: 70632kb

input:

28
200878223506436882933619847964496455022155117513398820563747455993172799881403389571477889821109288771413214004090719097929400406252135763028179112130390003528046316900603668569910008417315162907579003880220844686222148696041857432602133894827753998572080650383305777912447151917272483538029469449...

output:

27

result:

ok 1 number(s): "27"

Test #3:

score: 0
Accepted
time: 52ms
memory: 69428kb

input:

5187
2640352926124261912741724778991366987330659389621881876017670644497364093930668042530271338851702874394631009332660937266680740235862107353443518003194307853104942996827176097428402408674756368623972812842571069642405111849826172879369776309763468485788964245903781380419155348915131587410703749...

output:

6073

result:

ok 1 number(s): "6073"

Test #4:

score: 0
Accepted
time: 48ms
memory: 73756kb

input:

200000
2
2
2
2
1
2
1
1
2
2
1
1
1
2
2
1
1
2
1
1
2
2
1
2
2
2
1
1
1
1
2
2
1
2
1
2
1
1
2
2
1
1
1
2
1
1
2
1
2
2
2
2
1
2
2
1
1
1
2
1
1
1
1
1
2
1
2
2
1
1
1
2
2
2
1
1
2
1
1
2
1
2
1
1
1
2
2
2
1
1
1
1
2
1
2
1
1
2
2
1
1
2
1
1
2
1
2
2
1
2
1
2
2
1
1
2
1
1
1
2
2
2
1
2
2
1
1
2
2
2
2
1
2
1
1
2
1
2
2
1
1
1
1
2
2
2
2...

output:

15003749259

result:

ok 1 number(s): "15003749259"

Test #5:

score: 0
Accepted
time: 1388ms
memory: 158788kb

input:

200000
944176313232170622314
2590599414036674999101
753315073608896000424
9299685298577430049245
9361800333778142620806
8988699166328904060999
9606920674025578304023
4203331868598952026136
5183047027116137697788
3968714342776915029801
8130984095583566992354
3206443643596048048798
6248561214283254355...

output:

0

result:

ok 1 number(s): "0"

Test #6:

score: -100
Runtime Error

input:

200000
9
10
3
5
9
3
3
9
8
5
1
2
7
8
4
6
2
3
3
9
5
5
4
9
7
5
8
2
6
10
9
7
2
2
1
10
10
6
10
7
4
7
9
7
2
2
10
4
5
8
2
2
5
8
9
5
3
9
2
1
7
6
8
8
6
3
8
2
2
9
10
2
9
7
1
9
1
4
5
9
2
7
10
1
8
7
4
8
1
10
6
4
4
9
1
9
7
3
6
5
6
9
5
3
6
6
4
4
6
1
8
6
10
3
10
2
1
4
1
4
8
2
9
1
4
8
10
8
2
2
3
6
4
7
10
10
9
4
7
6...

output:


result: