QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#708327 | #9225. Fibonacci Fusion | ccccccyd | TL | 0ms | 0kb | C++14 | 1.5kb | 2024-11-03 21:26:34 | 2024-11-03 21:26:35 |
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;
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];
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');
}
sort(a+1,a+n+1,[](big i,big j){
return i.d!=j.d?i.d<j.d:i.a<j.a;
});
int k=2;//f[0]=f[1]<2<=ai+aj
auto cnt=[](big x,big y){
return mp[(x.h1-y.h1+mod1)%mod1*mod2+(x.h2-y.h2+mod2)%mod2];
};
rep(i,1,n){
while(f[k].d<a[i].d) k++;
// cerr<<i<<' '<<k<<'\n';
rep(j,max(0,k-10),max(M-1,k+20)){
ans+=cnt(f[j],a[i]);
}mp[a[i].h1*mod2+a[i].h2]++;
}
cout<<ans;
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: 0
Time Limit Exceeded
input:
6 50 8 8 5 72 354224848179261915070