QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#600535#9225. Fibonacci Fusionucup-team4352#WA 142ms128952kbC++231.3kb2024-09-29 17:10:432024-09-29 17:10:43

Judging History

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

  • [2024-09-29 17:10:43]
  • 评测
  • 测评结果:WA
  • 用时:142ms
  • 内存:128952kb
  • [2024-09-29 17:10:43]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define pii pair<ll,ll>
#define lowbit(x) (x&-x)
//#define log(x) (31^__builtin_clz(x))
using namespace std;
#define ld long double
int b[10000005];
ll fib[10000005];
const ll p=1000000000001117ll,sd=10;
bool cmp(string &a,string &b){
    if(a.size()!=b.size())return a.size()<b.size();
    return a<b;
}
void solve(){
    ld sq5=sqrtl(5),lg=log((1+sq5)/2)/log(10),lg5=log(sq5)/log(10);
    fib[1]=1;
    for(int i=1;i<=1e7;i++){
        b[i]=floor(lg*i+lg5);
        if(b[i]<=0)b[i]=1;
    }
    for(int i=2;i<=1e7;i++){
        fib[i]=fib[i-1]+fib[i-2];
        if(fib[i]>=p)fib[i]-=p;
    }
    int n;
    cin>>n;
    vector<string>s(n);
    fib[1]=1;
    for(int i=1;i<=n;i++){
        cin>>s[i-1];
    }
    sort(s.begin(),s.end(),cmp);
    map<ll,int>mp;
    ll ans=0;
    for(int i=0;i<n;i++){
        ll tmp=0;
        for(auto u:s[i]){
            tmp=(tmp*10+u-48)%p;
        }
        int loc=lower_bound(b+1,b+(int)1e7+1,s[i].size())-b;
        for(int i=max(loc-1,1);i<=loc+9&&i<=1e7;i++){
            ans+=mp[(fib[i]-tmp+p)%p];
        }
        mp[tmp]++;
    }
    cout<<ans<<"\n";
}
int 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: 111ms
memory: 120748kb

input:

6
50
8
8
5
72
354224848179261915070

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: 0
Accepted
time: 122ms
memory: 125628kb

input:

28
200878223506436882933619847964496455022155117513398820563747455993172799881403389571477889821109288771413214004090719097929400406252135763028179112130390003528046316900603668569910008417315162907579003880220844686222148696041857432602133894827753998572080650383305777912447151917272483538029469449...

output:

27

result:

ok 1 number(s): "27"

Test #3:

score: -100
Wrong Answer
time: 142ms
memory: 128952kb

input:

5187
2640352926124261912741724778991366987330659389621881876017670644497364093930668042530271338851702874394631009332660937266680740235862107353443518003194307853104942996827176097428402408674756368623972812842571069642405111849826172879369776309763468485788964245903781380419155348915131587410703749...

output:

5579

result:

wrong answer 1st numbers differ - expected: '6073', found: '5579'