QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#708365#9225. Fibonacci FusionccccccydTL 168ms339928kbC++141.8kb2024-11-03 21:47:312024-11-03 21:47:33

Judging History

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

  • [2024-11-03 21:47:33]
  • 评测
  • 测评结果:TL
  • 用时:168ms
  • 内存:339928kb
  • [2024-11-03 21:47:31]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define rep(i,l,r) for(int i(l),i##end(r);i<=i##end;++i)
#define per(i,r,l) for(int i(r),i##end(l);i>=i##end;--i)
using namespace std;
const int N=2e5+10,M=1e7;
const ll P0=1e17,mod1=1e9+7,mod2=1e9+9;
struct big{
    ll d,a,h1,h2;//v=a*10^d
    friend big operator+(big x,big y){
        //保证有 x<y<2x
        big z={y.d,((x.d==y.d)?x.a:x.a/10)+y.a,(x.h1+y.h1)%mod1,(x.h2+y.h2)%mod2};
        if(z.a>=P0) z.a/=10,z.d++;
        return z;
    }
    void ins(int x){//加一位 x
        a=a*10+x,h1=(h1*10+x)%mod1,h2=(h2*10+x)%mod2;
        if(a>=P0) a/=10,d++;
    }
}f[M],a[N];
int n; ll ans; char s[M]; unordered_map<ll,int> mp;
int inline cnt(big x,big y){
    return mp[(x.h1<y.h1?x.h1-y.h1+mod1:x.h1-y.h1)*mod2+(x.h2<y.h2?x.h2-y.h2+mod2:x.h2-y.h2)];
}
signed main(){
    // freopen("1.in","r",stdin);
    f[0]=f[1]={0,1,1,1};//f[0]=f[1]=1=1*10^0
    rep(i,2,M-1){
        f[i]=f[i-2]+f[i-1];
    } 
    cerr<<1.0*clock()/CLOCKS_PER_SEC<<"s\n";
    scanf("%d",&n);
    rep(i,1,n){
        scanf("%s",s+1);
        int len=strlen(s+1);
        rep(k,1,len) a[i].ins(s[k]-'0');
    }
    cerr<<1.0*clock()/CLOCKS_PER_SEC<<"s\n";
    sort(a+1,a+n+1,[](big i,big j){
        return i.d!=j.d?i.d<j.d:i.a<j.a;
    });
    cerr<<1.0*clock()/CLOCKS_PER_SEC<<"s\n";
    // if(n==200000&&a[1].d>1) return 0;
    int k=2;//f[0]=f[1]<2<=ai+aj
    rep(i,1,n){
        while(k<M&&f[k].d<a[i].d) k++;
        assert(k<M);
        rep(j,k,min(M-1,k+100)){
            ans+=cnt(f[j],a[i]);
        }mp[a[i].h1*mod2+a[i].h2]++;
        // cerr<<1.0*clock()/CLOCKS_PER_SEC<<"s\n";
    }
    cout<<ans;
    cerr<<1.0*clock()/CLOCKS_PER_SEC<<"s\n";
    return 0;
}//g++ -g my.cpp -o my -std=c++14 -O2  -Wall -Wextra -Wshadow -Wconversion

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 40ms
memory: 319412kb

input:

6
50
8
8
5
72
354224848179261915070

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: 0
Accepted
time: 84ms
memory: 320788kb

input:

28
200878223506436882933619847964496455022155117513398820563747455993172799881403389571477889821109288771413214004090719097929400406252135763028179112130390003528046316900603668569910008417315162907579003880220844686222148696041857432602133894827753998572080650383305777912447151917272483538029469449...

output:

27

result:

ok 1 number(s): "27"

Test #3:

score: 0
Accepted
time: 118ms
memory: 339928kb

input:

5187
2640352926124261912741724778991366987330659389621881876017670644497364093930668042530271338851702874394631009332660937266680740235862107353443518003194307853104942996827176097428402408674756368623972812842571069642405111849826172879369776309763468485788964245903781380419155348915131587410703749...

output:

6073

result:

ok 1 number(s): "6073"

Test #4:

score: 0
Accepted
time: 168ms
memory: 324268kb

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: -100
Time Limit Exceeded

input:

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

output:


result: